Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Build a Blog Reader iPhone App Exploring the Master-Detail Template Modifying the Master-Detail Template

Lex Lawless
Lex Lawless
1,773 Points

Stuck 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
Gareth Borcherds
9,372 Points

Try this [bookArray objectAtIndex:2] after the equal sign.

Lex Lawless
Lex Lawless
1,773 Points

Hi 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.

It is recommended that you know how to create Data Structures and understand them.