Possible Duplicate:
Why does NSArray arrayWithObjects require a terminating nil?
It is said that we need to always use a nil
as the last item for arrayWithObjects
:
NSArray *wordList = [NSArray arrayWithObjects: @"hello", @"world", nil];
Why can't arrayWithObjects
not require the nil
and just add the nil
for us. Some forum said that's because the nil
act as a sentinel for other methods... but isn't that an implementation issue that shouldn't concern the user of the class?
For example, if other languages require
list = [1 ,2, nil] # Ruby
to build an array, it can be somewhat weird.