使用可变参数列表创建 NSArray

发布于 2024-09-16 09:56:15 字数 175 浏览 6 评论 0原文

此数组便捷方法采用以 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

把人绕傻吧 2024-09-23 09:56:15

以空结尾的变量参数列表va_list,继续遍历参数列表,直到遇到占位符或标记,即nil

由于该方法无法知道您传递了多少个参数,因此它需要哨兵 (nil) 来告诉列表的结束位置。

Null terminated variable argument lists, or va_lists, keep walking the list of arguments until they encounter a placeholder or sentinel, which is nil.

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.

断桥再见 2024-09-23 09:56:15

标记对象列表的末尾。

这是来自 CocoaBuilder< 的讨论/a>.

To mark the end of the list of objects.

Here's a discussion from CocoaBuilder.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文