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!
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

Gerald Jackson
3,242 PointsCode Challenge: Create an NSArray property
Hi everyone, I have been trying to pass this challenge for hours now.
for the THViewController.m here is my code - --
import "THViewController.h"
@implementation THViewController
-
(void)viewDidLoad { [super viewDidLoad];
// Add your code below! // Remember the array property is called 'quotes' // And the label property is called 'quoteLabel'
self.quotes = [[NSArray alloc] initWithQuotes:
}
@end
for the THViewController.h here is my code --
import "UIViewController.h"
import "UILabel.h"
@interface THViewController : UIViewController
@property (nonatomic, strong) IBOutlet UILabel *predictionLabel;
@property (nonatomic, strong) NSArray *predictions;
-(IBAction)buttonPressed;
@end
what is it that I'm missing ? please help thanks
2 Answers

Matthew Reed
Courses Plus Student 17,986 PointsThere is no NSArray method named "initWithQuotes". You want to use "initWithObjects" and pass in NSString objects.

Gerald Jackson
3,242 Pointsthanks still no luck

Rashii Henry
16,433 PointsOnce you change initWithQuotes to to the correct convenience constructor just go ahead and add in the titles with the correct syntax(format).
Just like ----> initWIthObjects: @"(text goes here)",@"(text goes here)",@"(text goes here)", nil];
everything else looks correct.

Gerald Jackson
3,242 Pointsimport "THViewController.h"
@interface THViewController ()
@end
@implementation THViewController
-
(void)viewDidLoad { [super viewDidLoad];
// Add your code below! // Remember the array property is called 'quotes' // And the label property is called 'quoteLabel'
self.quotes = [[NSString alloc] initWithObjects:@"Haters gonna hate", @"Life is simple, not easy", @"Winners never quit, quitters never win", Nil];
}
-(void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
-(IBAction)buttonPressed {
self.quoteLabel.text = [self.quotes objectAtIndex:1];
@end

Rashii Henry
16,433 PointsPut it like this, you can't just post the code and expect us to know what you need right off the back.
you have to tell us the question and then explain to us what error you're receiving or what you're having difficulty understanding.
but you're having a problem because ---> self.quotes is not of type NSString. Remember you declared the quotes array in the header(.h) file.
you declared it as a NSArray. (I know you thought since you were assigning it strings that it would be of type NSString, but an array holds multiple strings and NSString is for only one at a time.)
also, nil should be all lowercase.
other than that you should be good to go man.

Rashii Henry
16,433 Pointsalso make sure all punctuation within the strings is exactly correct.
Stone Preston
42,016 PointsStone Preston
42,016 PointsCan you link the actual challenge?