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

Sam Chaudry
Sam Chaudry
25,519 Points

Crystal Ball - Code Challenge > Creating a Data Collection > Create an NSArray Property

On the code challenge for Creating data collection badge the compiler seems to be crashing all the time, not sure why. I've added my code for each of three steps, any chance someone can point me in the right direction?

Stage 1@property (nonatomic, strong) NSArray * quotes;

Stage 2 self.quotes= [[NSArray alloc]initWithObjects:@"Haters gonna hate", @"It is decidedly so", @"Life is simple, not easy", @"Winners never quit, quitters never win", Nil];

Stage 3 self.quotes.text= [quotes objectAtIndex:2];

21 Answers

Sam Chaudry
Sam Chaudry
25,519 Points

Glad you finished Antonio, I just logged in and saw the alert, try to be a bit more helpful next time

GRAYSON D SMITH
GRAYSON D SMITH
1,547 Points

The directions are wrong in this task. Nowhere does it ask you to use "It is decidedly so"...

Amit Bijlani
Amit Bijlani
Treehouse Guest Teacher

I think Sam just added that in but it is not supposed to be part of the answer.

GRAYSON D SMITH
GRAYSON D SMITH
1,547 Points

Thanks Amit.. yeah, not sure what was up. I was having some problems until I added that line in

Amit Bijlani
STAFF
Amit Bijlani
Treehouse Guest Teacher

In task 3 you have to assign the quote to the label which is called 'quoteLabel' not 'quotes'.

Sam Chaudry
Sam Chaudry
25,519 Points

Hi I just put in self.quoteLabel.text= [quotes objectAtIndex:2] it still seems to be crashing. Not sure what I'm doing wrong here?

Amit Bijlani
Amit Bijlani
Treehouse Guest Teacher

The array 'quotes' is a property so you have to refer to it as 'self.quotes'.

Sam Chaudry
Sam Chaudry
25,519 Points

Hi Amit I had another go at it and I still got an error as well as a message stating to contact the help desk. This is the code I've inputted in self.quoteLabel.text= [self.quotes objectAtIndex:1]; If you could explain what I'm doing wrong that would be much appreciated

Amit Bijlani
Amit Bijlani
Treehouse Guest Teacher

Your syntax is fine now. I just realized that when you initialized your array you added "It is decidedly so" as your second item while it is expecting "Life is simple, not easy".

Sam Chaudry
Sam Chaudry
25,519 Points

Awesome that sorted it out. Thanks Amit

Let me also add that I was trying to figure out the problem with my code for about an hour. The problem with my code was that I did not capitalize the 'L' in 'Life'. This caused my work to be wrong. Beware!

Amit Bijlani
Amit Bijlani
Treehouse Guest Teacher

Sorry about that, I have modified the challenge to be a bit more lenient.

Sam Chaudry
Sam Chaudry
25,519 Points

Thanks Angel great tip

Antonio Fullone
Antonio Fullone
1,019 Points

I'm trying to do this task but I always get an error : I do the exact same thing : 1step - @property (nonatomic, strong) NSArray *quotes; 2step - self.quotes = [NSArray alloc] initWithObjects: @"Haters gonna hate", @"Life is simple, not easy", @"Winners never quit, quitters never win", Nil]; and then it says : "Oops! It looks like Task 1 is no longer passing.". I've lost half hour on this but cannot understand where I am doing wrong, I also re-watched the video. What am I doing wrong?

Emmanuel Darmon
Emmanuel Darmon
6,115 Points

I think it's an error, but if you add @"It is decidedly so" in your code, it will work out! @"Haters gonna hate", @"It is decidedly so", @"Life is simple, not easy", @"Winners never quit, quitters never win", Nil];

Antonio Fullone
Antonio Fullone
1,019 Points

I finally solved it, I was missing to add the string "@"It is decidedly so", thanks to this post I found out the reason.

Maybe I missed out something but this is the description of the task :

Switch to the implementation file. Within the 'viewDidLoad' method allocate and initialize the 'quotes' property to the following quotes: 'Haters gonna hate', 'Life is simple, not easy', 'Winners never quit, quitters never win'.

I added the string and finished the task. :)

''' Stage 1@property (nonatomic, strong) NSArray * quotes;

Stage 2 self.quotes= [[NSArray alloc]initWithObjects:@"Haters gonna hate", @"Life is simple, not easy", @"Life is simple, not easyIt is decidedly so", @"Winners never quit, quitters never win", Nil];

this is wrong-->Stage 3 self.quotes.text= [quotes objectAtIndex:2]; this is right-->Stage 3 self.quoteLabel.text = [self.quotes objectAtIndex:1];

'''

Thanks guys, this one has been really annoying me. Stupid me had written down my notes wrong :-\

Sam Chaudry
Sam Chaudry
25,519 Points

Yeah I decided to put that in just to shake things up lol. Apologies if it seem confusing....

nawrouz karim
nawrouz karim
1,295 Points

i am at stage 3 and the code below hits back an error, this is the same syntax from my program on Xcode so i don't understand where i'm going wrong with it.

    self.quoteLabel.text = [self.quotes objectAtIndex:1];
GRAYSON D SMITH
GRAYSON D SMITH
1,547 Points

That actually looks right to me too Nawrouz. Maybe check to make sure you didn't change anything else by mistake?

Ghaz Sabh
Ghaz Sabh
5,005 Points

I'm so done with stupid code challenge things, I'm going to cancel my course with tree house. Thats my best answer, I spent more times trying to figure out where is the issue can't find. Good luck guys.

Amit Bijlani
Amit Bijlani
Treehouse Guest Teacher

We are here to help you. All you need to do is share your code and where you were having trouble and we'd gladly point you in the right direction. It can be hard initially but once you get a hang of the concepts and syntax it will get easier.

Ghaz Sabh
Ghaz Sabh
5,005 Points

Thank you so much for your replay Amit, I'm stuck on task 2, not sure how task 3 will be :)

self.quotes = [[NSArray alloc] initWithObjects: @"Haters gonna hate", @"Life is simple, not easy", @"Life is simple, not easy It is decidedly so", @"Winners never quit, quitters never win", Nil];

Amit Bijlani
Amit Bijlani
Treehouse Guest Teacher

I copied and pasted your code above and it passed for Task 2. Did you make sure to switch over to the THViewController.m and enter your code within the viewDidLoad method?

in stage1, when i tried :

@property (nonatomic, strong) NSString *quotes;

and it passed.. dunno if its a bug for it

:)

thanks Amit, I've learned a lot from you!(guys)

stage 3. self.quoteLabel.text=[self.quotes objectAtIndex:1]; where is the problem?

Michael Maloof
Michael Maloof
4,581 Points

Can someone please add the final coding for all three stages? All the instructional errors involved in the question have made the forum really confusing to read. Thanks guys (still a great lesson btw).

nan zhou
PLUS
nan zhou
Courses Plus Student 18,273 Points

Here is my answer for stage 2 and 3. It successfully passed the challenge.

// Stage 2
self.quotes= [[NSArray alloc]initWithObjects:@"Haters gonna hate", @"Life is simple, not easy", @"Winners never quit, quitters never win", Nil];

//Stage 3
self.quoteLabel.text = [self.quotes objectAtIndex:1];