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! While you're at it, check out some resources Treehouse students have shared here.

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 Objective-C Basics (Retired) Foundation Framework NSArray

Challenge Task question!

Declare an NSArray variable named "drinks" and initialize it with three strings: "juice", "water", and "coffee".

tried

NSArray *drinks[[NSArray alloc] initWithObjects:@"juice", @"water", @"coffee", nil];

Correct code with explanation would be appreciated.

Thanks!

Also just tried

NSArray *drinks[[NSArray alloc] initWithStrings[@"juice", @"water", @"coffee", nil];

because I thought since it asked for string strings not objects that might word.

3 Answers

Troy Fine
Troy Fine
7,592 Points

Hi Tyler,

Should be:

NSArray *drinks = [[NSArray alloc] initWithObjects:@"juice", @"water", @"coffee", nil];

Explanation: You were close, probably just one cup of coffee short of having it right the first time. Just needed the equals sign in there after declaring *drinks. Don't worry I make typing errors like that all the time. Less frequently the more I code but it still happens to the best of us.

This won't work either

NSArray *drinks = [[NSArray alloc] initWithStrings:@"juice", @"water", @"coffee", nil];

Hello, try this one. I passed the challenge. NSArray * drinks = [NSArray arrayWithObjects: @"juice", @"water", @"coffee", nil] ;