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

NSArray challenge

NSArray *drinks = [ @"juice", @"water", @"coffee" ]; for (NSString *string in drinks) { NSLog(@"%@", string); }

What am I doing wrong? specially on the "for in" loop

2 Answers

Mike Baxter
Mike Baxter
4,442 Points

First, try to output the count of your array to see if it actually has 3 items.

NSLog(@"%d", [drinks count]);

It'll probably return 0. It looks like you may have missed the @ before the NSArray literal. Should look like this:

NSArray *drinks = @[ @"juice", @"water", @"coffee" ];

for (NSString *string in drinks) {
    NSLog(@"%@", string);
}

Looks almost the exact same, but the crucial code in making an array with literals is

@[obj 1, obj 2, obj 3]

Thank you