NSArray creation with variable argument lists

ぐ巨炮叔叔 提交于 2019-12-17 16:53:00

问题


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?


回答1:


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.




回答2:


To mark the end of the list of objects.

Here's a discussion from CocoaBuilder.



来源:https://stackoverflow.com/questions/3602458/nsarray-creation-with-variable-argument-lists

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!