预期为“;”在“ for”语句说明符中(iOS) [英] Expected ';' in 'for' statement specifier (iOS)

查看:375
本文介绍了预期为“;”在“ for”语句说明符中(iOS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在iOS中尝试以下代码进行快速枚举时...

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

推荐答案

该语法称为快速枚举,是Objective的一部分-C 2.0,因此,如果您运行的是2.0版之前的编译器,它将无法使用。

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

这篇关于预期为“;”在“ for”语句说明符中(iOS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆