开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜