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 trialTyler Phillips
495 PointsChallenge 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!
3 Answers
Troy Fine
7,592 PointsHi 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.
Tyler Phillips
495 PointsThis won't work either
NSArray *drinks = [[NSArray alloc] initWithStrings:@"juice", @"water", @"coffee", nil];
Xiang Liu
24,339 PointsHello, try this one. I passed the challenge. NSArray * drinks = [NSArray arrayWithObjects: @"juice", @"water", @"coffee", nil] ;
Tyler Phillips
495 PointsTyler Phillips
495 PointsAlso 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.