Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

ultranerd
1,060 PointsSignificance of 'nil' in NSArray?
What is the purpose of ending NSArray with 'nil' in Objective C
-(NSArray *) phrases {
if (phrases == nil) {
phrases = [[NSArray alloc] initWithObjects:
@"Phrase 1",
@"Phrase 2",nil);
}
return phrases;
}
2 Answers

Chris Campisi
1,640 PointsFrom my understanding, nil allows the program to understand that it has reached the end of the array.

Yoav Zoldan
9,485 PointsYou can use the array literal and it's much shorter, like this: phrases = @[@"phrase 1",@"phrase 2"];

ultranerd
1,060 PointsI appreciate it. Thanks.
ultranerd
1,060 Pointsultranerd
1,060 PointsThank you, sir.