Purpose of "nil' at the end of Initializing Array in Objective-C
I have seen and done initialization of arrays and all put "nil" at the end of initialization but never question, why it is required to put there?
Plus if you are initializing your array in a loop, is it still necessary to put nil at the end of array? for example.
array = [[NSMutableArray alloc] init];
for (int i = 0 ; i < 10; i++)
{
[array addObject:@"1"];
}
// now this line is required or not after i exit the loop?
[array ad开发者_开发技巧dObject:nil];
This concept is called nil-termination, and it's purpose is to provide a sentinel to the receiving function or method of where the variable argument list ends.
精彩评论