我一直在尝试参加酷派学校的Objective-C课程,但我一直坚持挑战10/11。它要我创建一个数组变量,然后访问值。这就是它给我的:
NSArray *apps = @[@"AngryFowl", @"Lettertouch", @"Tweetrobot"];
NSLog (@"%@", apps[1]);
在线编译器抛出以下内容:
main.m: In function ‘main’:
main.m:7:17: error: stray ‘@’ in program
NSArray *apps = @[@"AngryFowl", @"Lettertouch", @"Tweetrobot"];
^
main.m:7:31: warning: left-hand operand of comma expression has no effect [-Wunused-value]
NSArray *apps = @[@"AngryFowl", @"Lettertouch", @"Tweetrobot"];
^
main.m:7:47: warning: left-hand operand of comma expression has no effect [-Wunused-value]
NSArray *apps = @[@"AngryFowl", @"Lettertouch", @"Tweetrobot"];
^
main.m:7:62: error: expected ‘:’ before ‘]’ token
NSArray *apps = @[@"AngryFowl", @"Lettertouch", @"Tweetrobot"];
^
可能是我的问题吗?
答案 0 :(得分:0)
当我与http://rextester.com/l/objectivec_online_compiler合作时,遇到了相同的错误:
//gcc 5.0.4
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSArray *apps = [NSArray arrayWithObjects:@"AngryFowl", @"Lettertouch", @"Tweetrobot", nil];
NSLog (@"%@", [apps objectAtIndex:1]);
[pool drain];
return 0;
}
当我使用
arrayWithObjects
和
objectAtIndex
有效:
2018-10-05 06:11:35.286 a.out[21957] Lettertouch