NSArray creation with variable argument lists

后端 未结 2 2019
忘掉有多难
忘掉有多难 2020-12-06 22:58

This array convenience method takes a comma-separated list of objects ending with nil.

myArray = [NSArray arrayWithObjects:aDate, aValue, aStrin         


        
相关标签:
2条回答
  • 2020-12-06 23:27

    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.

    0 讨论(0)
  • 2020-12-06 23:48

    To mark the end of the list of objects.

    Here's a discussion from CocoaBuilder.

    0 讨论(0)
提交回复
热议问题