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

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

arrays

NSArray *booksArray = [NSArray arrayWithObjects : @"Hamlet",@"King Lear",@"Othello",@"Macbeth",nil];

have this array now second questin is : Create a string variable called 'bookTitle' and assign it the third item from the 'booksArray'.

my answer was

NSString *bookTitle = [self.booksArray objectAtIndex:2];

but it showing error can you help me to fix it.

3 Answers

Hi, Sayana Narayanan:

You do not need to associate self with booksArray because of the scoping context of this challenge.

Correcting that mistake, you should have the following code typed:

NSString *bookTitle = [booksArray objectAtIndex:2]; 

Pro tip

Even better, though it might not be recognized by the challenge for this problem, you can access the index you want of an array using square brackets like most languages.

You can also simplify NSArray instantiations with the literal syntax:

NSArray *booksArray = @[@"Hamlet",@"King Lear",@"Othello",@"Macbeth"]; 
NSString *bookTitle = booksArray[2]; 

Thanks

booksArray in this situation is not a class property, so you don't need the self part to access it.

Try removing "self".