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 Simple iPhone App (iOS7) Refactoring into a Model Creating a Custom Class

I thought I did allocate and initialize _quotes.

Bummer! Remember to allocate and initialize the instance variable '_quotes' and return it from the method named 'quotes'.

Quote.h
@interface Quote : NSObject

// Add property here

@property (strong, nonatomic, readonly) NSArray *quotes;

- (NSString *) randomQuote;

@end
Quote.m
#import "Quote.h"

@implementation Quote

- (NSString *) randomQuote {
if (_quotes == nil){
   _quotes = NSArray [[NSArray alloc] initWithObjects:@"Happy, Happy, Happy", @"Your gullible", @"Say cheese", nil]; 
    }
    return _quotes;
}

@end

3 Answers

your code is almost correct, with a few minor issues:

you added your code to the randomQuote method, you are supposed to implement a new method. called quotes that returns an NSArray. also, you had an extra NSArray out in front of your alloc call (NSArray [[NSArray alloc]) . remove that:

@implementation Quote

- (NSArray *) quotes {
if (_quotes == nil){
   _quotes = [[NSArray alloc] initWithObjects:@"Happy, Happy, Happy", 
   @"Your gullible", @"Say cheese", nil]; 
    }
    return _quotes;
}


- (NSString *) randomQuote {

    return @"Some Quote";
}

@end

and remove the read only attribute from your property. it messes up the challenge and wont accept it with it in there:

@property (strong, nonatomic) NSArray *quotes;

Okay, did what you said and I'm still getting the same message, can you find anything else wrong with the code?

Okay, did what you said and I'm still getting the same message, can you find anything else wrong with the code?

I passed task 1 and 2 using the code I posted above. make sure you typed everything in correctly

Still isn't working, I even tried to copy and paste the code and had no luck with it.