Really beginner question here.
这里真的是初学者的问题。
I have an NSArray of images which in its last line has an error in Xcode saying that the "initializer element is not constant".
我有一个NSArray的图像,它的最后一行在Xcode中有一个错误,说“初始化元素不是常数”。
any help please?
有什么帮助吗?
1 个解决方案
#1
2
You're initializing your NSArray outside of a valid scope (ie, not inside a function or method).
您正在有效范围之外初始化NSArray(即,不在函数或方法内)。
For example, the following will produce your error:
例如,以下内容将产生您的错误:
NSArray * foo = [NSArray array];
int main(int argc, char * argv[]) {
return 0;
}
To fix it, you'd do something like:
要解决它,你会做类似的事情:
NSArray * foo = nil;
int main(int argc, char * argv[]) {
foo = [NSArray array];
return 0;
}
#1
2
You're initializing your NSArray outside of a valid scope (ie, not inside a function or method).
您正在有效范围之外初始化NSArray(即,不在函数或方法内)。
For example, the following will produce your error:
例如,以下内容将产生您的错误:
NSArray * foo = [NSArray array];
int main(int argc, char * argv[]) {
return 0;
}
To fix it, you'd do something like:
要解决它,你会做类似的事情:
NSArray * foo = nil;
int main(int argc, char * argv[]) {
foo = [NSArray array];
return 0;
}