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

cameryn smith
cameryn smith
2,828 Points

Can someone help me with task1 of creating a NSArray for the Blog Reader App, Thank you?

I have tried different ways of initializing a new NSArray but it didn't help.

@property (strong, nonatomic) NSArray *booksArray;

self.booksArray.text = [[NSArray alloc] initWithObjects:@"1",nil]; or self.booksArray.text = [[NSArray alloc] arrayWithObjects:@"1",nil];

I'm still lossed. -__-

Amit Bijlani

1 Answer

Stone Preston
Stone Preston
42,016 Points

the challenge states: Create an array named 'booksArray' with the following book titles: 'Hamlet', 'King Lear', 'Othello', 'Macbeth'. it doesnt say to create an array property. you just want to create a regular array variable

to create an array you simply declare an object of type NSArray, name it, and allocate and initialize it with values using the initWithObjects method.

NSArray *someArray = [[NSArray alloc] initWithObjects:@"some string", @"someOtherString", nil];

you could also create an array using an array literal:

NSArray *someArray = @[@"some string", @"some other string"];

the challenge tells you what string to put in your array so use the above code as an example. instead of naming it someArray name it booksArray

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

using literal syntax looks like this:

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

I prefer using literal syntax since its much shorter and is very clean.

cameryn smith
cameryn smith
2,828 Points

Dude thank you so much, I literally had a brain fart on how to create an NSArray and I have been driving myself crazy for the past 6 hours.