1

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?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Saboteur Kid
  • 85
  • 4
  • 13

1 Answers1

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