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

不打扰是莪最后的温柔 提交于 2019-12-11 06:22:27

问题


when I try the following code in iOS for fast enumeration...

NSArray *array = [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?


回答1:


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


来源:https://stackoverflow.com/questions/7084213/expected-in-for-statement-specifier-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!