0

NSArray arrayWithObjects needs nil at the end, NSString stringWithFormat and NSLog() doesn't. Why?

[NSArray arrayWithObjects:<#(id), ...#>, nil] 

[NSString stringWithFormat:<#(NSString *), ...#>]

NSLog(<#NSString *format, ...#>)
William Entriken
  • 37,208
  • 23
  • 149
  • 195
  • 2
    possible duplicate of [Why do parameter lists in certain cocoa methods end with a nil?](http://stackoverflow.com/questions/2477985/why-do-parameter-lists-in-certain-cocoa-methods-end-with-a-nil) – jscs Apr 02 '12 at 04:56
  • see also: http://stackoverflow.com/questions/1309535/why-does-nsarray-arraywithobjects-require-a-terminating-nil – jscs Apr 02 '12 at 04:58

1 Answers1

4

Because -stringWithFormat: and NSLog can infer the number of arguments based on their format strings (the first argument). -arrayWithObjects: can't.

Wevah
  • 28,182
  • 7
  • 83
  • 72
  • Thank you, yes I was dupe of http://stackoverflow.com/questions/2477985/why-do-parameter-lists-in-certain-cocoa-methods-end-with-a-nil – William Entriken Apr 02 '12 at 23:43