when I try the following code in iOS for fast enumeration...
NSArray *arra开发者_如何学Goy = [NSArray arrayWithObjects:
@"Hefeweizen", @"IPA", @"Pilsner", @"Stout", nil];
for (NSString *element in array)
NSLog(@"Beer: %@", element);
... I get this error:
Expected ';' in 'for' statement specifier
Do you know what is wrong?
That syntax is called fast enumeration and is part of Objective-C 2.0, so if you're running a pre-2.0 version of the compiler it won't work.
The standard syntax which it sounds like the compiler is expecting is something like this:
for (int i = 0; i < [array count]; i++) {
NSString *element = [array objectAtIndex:i];
NSLog (@"Beer: %@", element);
}
精彩评论