I'm new to objective-C. I'm just read some of article, and I saw that when init Array or Set, the writer do something like:
NSArray *list=[[NSArray alloc] initWithObjects:@"Andy",@"Erik",@"Aaron",nil];
I'm try to not use nil and nothing change, so, what is the point of nil when init an array or a set?
Asked
Active
Viewed 50 times
1

rmaddy
- 314,917
- 42
- 532
- 579

Saboteur Kid
- 85
- 4
- 13
-
1This should answer your question - http://stackoverflow.com/questions/1309535/why-does-nsarray-arraywithobjects-require-a-terminating-nil – tpatiern Sep 07 '15 at 03:13
-
thanks, @Chaikitty, I didn't found that one :) – Saboteur Kid Sep 07 '15 at 03:15
1 Answers
0
That's how the 'method' 'knows' that you've given it the last item in the list so it can know for sure when it reaches the end of the arguments for the method.
NSArray *listdemo = [[NSArray alloc] initWithObjects:@"Andy",@"Erik",@"Aaron",nil];
The method is iterating through the list until it finds nil. If it doesn't, it runs off the end and Bad Things happen.

Mayank Patel
- 3,868
- 10
- 36
- 59