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 trialcameryn smith
2,828 PointsCan 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. -__-
1 Answer
Stone Preston
42,016 Pointsthe 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
2,828 Pointscameryn smith
2,828 PointsDude 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.