Welcome to the Treehouse Community
Looking to learn something new?
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?
Amit BijlaniTreehouse 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:
You need to access the item from the array which is called
booksArrayfor some reason you have
Since you are accessing an item from an array and not inserting an item the method you want to use is
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?
Stefan Bjornsson3,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?