Xcode 4.5 中数组的新语法?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11860668/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
New syntax for arrays in Xcode 4.5?
提问by trojanfoe
Possible Duplicate:
Apple LLVM 4.0 new features on Xcode 4.4 (Literals)
I am using Xcode 4.5 and would like to use the new syntax to adding objects to arrays, in my old code I have:
我正在使用 Xcode 4.5,并希望使用新语法将对象添加到数组,在我的旧代码中:
NSArray *array = [[NSArray alloc] initWithObjects: rabbit, chicken, owl, nil];
NSArray *array = [[NSArray alloc] initWithObjects: rabbit, chicken, owl, nil];
What is the correct way to use the new syntax that is being introduced, for example:
使用正在引入的新语法的正确方法是什么,例如:
@[rabbit, chicken, owl]
@[兔子,鸡,猫头鹰]
TIA.
TIA。
回答by Tutankhamen
Your code is correct, i.e.:
您的代码是正确的,即:
NSArray *array = @[ rabbit, chicken, owl ];
回答by trojanfoe
What you have is correct. Here is some more documentationon the subject.
你所拥有的是正确的。这是有关该主题的更多文档。