Reputation: 149
I'm trying to append a string with a number and I'm using a for loop to do it. For some reason though I'm getting the error "Expected identifier."
How do I get rid of this issue in objective C?
for (int i=0; i<10000; i++)
{
int num = 0;
num = num + i;
NSString *current = [@"/current%d.html", num];
NSString *filePath = [basePath stringByAppendingString:current];
// NSLog(@"current");
Here's a snippet of my code where I'm getting the error.
Upvotes: 0
Views: 44
Reputation: 579
Try changing [@"/current%d.html", num];
to
[NSString stringWithFormat:@"/current%d.html", num];
When you enclose your statement in []
, Obj-C expects the statement to be a message-receiver pair. Here the +(NSString *)stringWithFormat:(NSString *)
class method receives the NSSting
@"/current%d.html", num"
message/parameter.
Don't know all the proper terminology, but thats the get of it I believe.
And as Josue pointed out, num
will be the same as i
in your code. Perhaps you meant to initialize before the for
loop?
Upvotes: 1