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 trialRobert Maidla
15,612 PointsI can't get passed the task that requires me to create an array with given entry titles although everything seems legit.
I don't understand what is wrong with my code. The task requires me to create an array named 'booksArray' and pass it the values that I've given it. I'm only getting an error which tells me to check my syntax or variable name.
NSArray *booksArray = @[@"Hamlet", "King Lear", @"Othello", @"Macbeth", nil];
4 Answers
Caleb Kleveter
Treehouse Moderator 37,862 PointsThis is what I passed with:
NSArray *booksArray = [[NSArray alloc] initWithObjects:@"Hamlet", @"King Lear", @"Othello", @"Macbeth", nil];
arshin
17,770 PointsUsage of a better method, combining your initialization and assignment:
NSArray *booksArray = [NSArray arrayWithObjects: @"Hamlet", @"King Lear", @"Othello", @"Macbeth", nil];
Charles Zhang
2,032 Pointsis this objective-c?
Robert Maidla
15,612 PointsObjective-c, yes but I managed to clear the task already :)
Charles Zhang
2,032 Pointsis this objective-c?
arshin
17,770 PointsYes, the code above is in Objective-C
Caleb Kleveter
Treehouse Moderator 37,862 PointsCaleb Kleveter
Treehouse Moderator 37,862 PointsCode challenges can be finicky, so even though I think your code is legitimate, it's not what they wanted.
Robert Maidla
15,612 PointsRobert Maidla
15,612 PointsAh yes, thank you. Managed to pass it with your code although I tried using several different approaches including this one prior to asking a question.
Caleb Kleveter
Treehouse Moderator 37,862 PointsCaleb Kleveter
Treehouse Moderator 37,862 PointsI'm glad you got it!