【发布时间】:2018-07-21 17:55:31
【问题描述】:
我一直在努力学习 Cool school 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"];
^
我的问题可能是什么?
【问题讨论】:
-
Objective-C literals 自 Apple LLVM Compiler 4.0 (AFAIR Xcode 6) 起可用。在线编译器显然不支持它们。
-
谢谢!!拿出笔记本电脑并在 xcode 中完成它,它工作了
-
对于在线编译器你必须使用经典的
[NSArray arrayWithObjects:@"AngryFowl", @"Lettertouch", @"Tweetrobot", nil];
标签: objective-c nsarray