开发者

Expected ';' in 'for' statement specifier (iOS)

开发者 https://www.devze.com 2023-03-28 07:49 出处:网络
when I try the following code in iOS for fast enumeration... NSArray *arra开发者_如何学Goy = [NSArray arrayWithObjects:

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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号