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.

Paul Denlinger
3,292 PointsProblem 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
Treehouse Guest TeacherYour 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];
You need to access the item from the array which is called
booksArray
for some reason you havebookTitle
Since you are accessing an item from an array and not inserting an item the method you want to use is
objectAtIndex
.

Brian Stevens
7,906 PointsI 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
Treehouse Guest TeacherIn 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

Brian Stevens
7,906 PointsExcellent, thank you! That makes sense.

Stefan Bjornsson
3,362 PointsI´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
Treehouse Guest TeacherThat is the wrong method. You are supposed to use objectAtIndex
. Please read my explanation above.
Paul Denlinger
3,292 PointsPaul Denlinger
3,292 PointsThank you, got it!
BTW, enjoy your lectures very much. You explain things very well. Thank you.