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

(Master-Detail Template) Create an array named 'booksArray' with the following book titles : 'Hamlet', 'King Lear', 'Othello', 'Macbeth'.

Can someone please help me out ? I can't understand the question. I don't know which part I should start to code at.

3 Answers

Chris Rhode
Chris Rhode
1,447 Points

Hi

This is an exercise in NSArray Literals - you can type it in a couple of different ways to get the same result

Type1 NSArray *array name = [[NSArray alloc] initWithObjects:@"array name 1",@"array name 2",......,nil];

Type2 NSArray *array name = [NSArray arrayWithObjects:@"array name 1",@"array name 2",......,nil];

I believe there may even be a shorter way of doing it but can't remember off the top of my head

I have the same question, I thought I did right but dont know why what's wrong here. Can somebody please help me?

           self.booksArray = [NSArray arrayWithObjects:
                    @"Hamlet",
                    @"King Lear",
                    @"Othello",
                    @"Macbeth",
                    nil];
            ```
Aaron Arkie
Aaron Arkie
5,345 Points

Hello, it should be in a form like this.. i'm not sure about objective C as i'm more familiar with Java but it should be similar. So its telling you to make an array called booksArray and its values are that of a string so first lets declare the array and what datatype it holds.

Form:

arraytype[] arrayname;

substitute the values:

String[] booksArray;

lastly set the book titles as a string to the array which should end up looking like this:

Form:

 arraytype[] arrayname = {string,string,string,string};

again substitute the values;

String[] booksArray = {"Hamlet", "King Lear", "Othello", "Macbeth"};

and that wraps it up i hope that helps.