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

Code 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

Stone Preston
Stone Preston
42,016 Points

Can you link the actual challenge?

2 Answers

Matthew Reed
PLUS
Matthew Reed
Courses Plus Student 17,986 Points

There is no NSArray method named "initWithQuotes". You want to use "initWithObjects" and pass in NSString objects.

thanks still no luck

Rashii Henry
Rashii Henry
16,433 Points

Once 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.

import "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
Rashii Henry
16,433 Points

Put 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
Rashii Henry
16,433 Points

also make sure all punctuation within the strings is exactly correct.