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


Problem with Modifying the Master-Detail Template Code Challenge

Have managed to pass the first challenge task with the following line of code: NSArray *booksArray = [NSArray arrayWithObjects:@"Hamlet", @"King Lear", @"Othello", @"Macbeth", nil];

Problems happen with the second challenge: Create a string variable called 'bookTitle' and assign it the third item from the 'booksArray'.

My code is: NSString *bookTitle = [bookTitle insertObjectAtIndex:2];

Problem is that after I enter this line of code, it says that the first challenge is also broken. What's wrong?

3 Answers

Amit Bijlani
Amit Bijlani
Treehouse Guest Teacher

Your first line of the code is perfect. The second line of code has a couple of issues on the right side of the equal sign.

Looking at your code:

[bookTitle insertObjectAtIndex:2];
  1. You need to access the item from the array which is called booksArray for some reason you have bookTitle

  2. Since you are accessing an item from an array and not inserting an item the method you want to use is objectAtIndex.

Thank you, got it!

BTW, enjoy your lectures very much. You explain things very well. Thank you.

I was stuck on this for a good hour because I was using "self.booksArray". Why is this not correct? What is it about "self" that I'm missing? Does it have to do with not declaring "booksArray" as a property?

Amit Bijlani
Amit Bijlani
Treehouse Guest Teacher

In the case of this code challenge you are declaring a local variable booksArray. You would use the keyword self only if you defined a property but in this case there is no view controller where you defining a @property called booksArray

Excellent, thank you! That makes sense.

Stefan Bjornsson
Stefan Bjornsson
3,362 Points

Iยดm having problem at passing the 2nd task. NSString *bookTitle = [booksArray insertObjectAtIndex:2]; This will give me the error: 'Make sure you declare a string called 'bookTitle' and object in the array using the method 'objectAtIndex'. Can anyone help out?

Amit Bijlani
Amit Bijlani
Treehouse Guest Teacher

That is the wrong method. You are supposed to use objectAtIndex. Please read my explanation above.