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

iOS Build a Simple iPhone App (iOS7) Creating a Data Collection Implementing an Array

Significance 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

From my understanding, nil allows the program to understand that it has reached the end of the array.

Thank you, sir.

Yoav Zoldan
Yoav Zoldan
9,485 Points

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

I appreciate it. Thanks.