使用可变参数列表创建 NSArray
此数组便捷方法采用以 nil
结尾的以逗号分隔的对象列表。
myArray = [NSArray arrayWithObjects:aDate, aValue, aString, nil];
nil
的目的是什么?
This array convenience method takes a comma-separated list of objects ending with nil
.
myArray = [NSArray arrayWithObjects:aDate, aValue, aString, nil];
What is the purpose of the nil
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以空结尾的变量参数列表或
va_list
,继续遍历参数列表,直到遇到占位符或标记,即nil
。由于该方法无法知道您传递了多少个参数,因此它需要哨兵 (
nil
) 来告诉列表的结束位置。Null terminated variable argument lists, or
va_list
s, keep walking the list of arguments until they encounter a placeholder or sentinel, which isnil
.Since the method has no way of knowing how many arguments you are passing, it needs the sentinel (
nil
) to tell where the list ends.标记对象列表的末尾。
这是来自 CocoaBuilder< 的讨论/a>.
To mark the end of the list of objects.
Here's a discussion from CocoaBuilder.