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

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

Don't understand why this is wrong. The error message I get is to make sure I declare the variable and to check my syntax. I also tried the short version and that was not accepted either:

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

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

4 Answers

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

I've spotted 2 very subtle errors here @"water". "@coffee"

  1. you should put a comma , after @"water", not a fullstop .
  2. "@coffee" should be @"coffee".

The rest of your code is fine

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

Thank you for catching that. I had rewritten this answer multiple times and I think my fingers were getting buggy. The problem still though is that using the code:

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

which as far as I can tell has no errors in it, still gives the error: "Make sure you created a NSString with the correct variable name, and check your syntax!"

Any ideas?

William Li
William Li
Courses Plus Student 26,868 Points

Really? I copied and pasted the new line of code you posted and it passed

Imgur

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

I saw that there but never clicked it. I thought it was just a link to the course I guess.

Right, when student posts question to the forum from within a video/code challenge, there're always the link to the origin provided on the right of the forum post. Without this piece of info, we may have to ask the questioner each time "what problem you're referring to?", lol, very unproductive.

I like reading forum questions sometimes, helps with learning

I agree 100%; Some say that you'll learn better by teaching and helping others learn. That's what I believe too. By seeing various problems student posted on the forum, answering them myself; or reading how they were answered by other people, really enriches my knowledge as a developer.

There's only so much one can learn on his/her own; software development isn't a solo act on the grand stage of Broadway; good product is built as a collaboratively effort by a team of developers helping each others; answering each others' questions and solving bugs; that, in a sense, is what we have been doing in this forum, isn't it.

Well that's annoying. Must be a bug or something. Here I am spending over an hour trying to figure out the "right" answer and I was right the first time. Thanks, I'll email support and let them know.

Btw, how did you go to the question to check it? Is there a link somewhere on the forum?

btw I just restarted my computer and now it passes. Sheesh.

William Li
William Li
Courses Plus Student 26,868 Points

Abbey, sorry that you've experienced such issue with the code challenge; I'm sure it's frustrating.

Btw, how did you go to the question to check it? Is there a link somewhere on the forum?

Imgur

There's link to the original challenge on the right.

Oh!! Thank you, I saw that there but never clicked it. I thought it was just a link to the course I guess. I don't know what I thought, it didn't really register. I like reading forum questions sometimes, helps with learning, but it's often not helpful without knowing what they are referring to. :)