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 trialLex Lawless
1,773 PointsStuck on a question regarding objectAtIndex
I created an array called bookArray. Now the quiz asks me to create string variable and assign it the value of the 3rd item in the Array using objectAtIndex. I cannot get the right syntax by following the code written by Amit in the video. Please help.
I tried the following and it doesn't work:
NSString *bookTitles = bookArray [objectAtIndex:2.row];
1 Answer
Gareth Borcherds
9,372 PointsTry this [bookArray objectAtIndex:2] after the equal sign.
Lex Lawless
1,773 PointsLex Lawless
1,773 PointsHi Gareth,
Sensational it works!
I put:
NSArray *booksArray = [[NSArray alloc] initWithObjects:@"Hamlet",@"King Lear", @"Othello",@"Macbeth", nil];
NSString *bookTitle = [booksArray objectAtIndex:2];
The frustrating thing is this syntax is never discussed in the videos. They put in the videos:
NSString *object = [self.titlesArray objectAtIndex:indexPath.row];
Thanks again.
arshin
17,770 Pointsarshin
17,770 PointsIt is recommended that you know how to create Data Structures and understand them.