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

help

i am wondering if anyone else can help with this question

What is the question?

7 Answers

not really sure why your code isnt working. Everything looks good. Here is the implementation file that worked for me:

#import "Quote.h"

@implementation Quote

- (NSString *) randomQuote {

    return @"Some Quote";
}

- (NSArray *)quotes {

    if (_quotes == nil) {

        _quotes = [[NSArray alloc] initWithObjects:@"a", @"b", @"c", nil];

    }

    return _quotes;

}

@end

your method looks right to me. this is what I passed it with

- (NSArray *)quotes {

    if (_quotes == nil) {

        _quotes = [[NSArray alloc] initWithObjects:@"a", @"b", @"c", nil];

    }

    return _quotes;
}

here is the .h file

@interface Quote : NSObject

// Add property here

@property (nonatomic, strong) NSArray *quotes;

- (NSString *) randomQuote;

@end

this is what i was asked.. Switch to the implementation file and implement a 'quotes' method which will allocate and initialize the _quotes instance variable only if it is 'nil'. Initialize the array with any three strings.

this is the code i wrote and it said it is incorrect

  • (NSArray *) quotes { if (_quotes == nil){ _quotes = [[NSArray alloc] initWithObjects:@"It is Certain", @"It is Decidedly so", @"The answer is in your heart", nil]; } return _quotes; }

still not passing through :/ my whole page looks like this... "

import "Quote.h"

@implementation Quote

  • (NSArray *)quotes {

    if (_quotes == nil) {

    _quotes = [[NSArray alloc] initWithObjects:@"a", @"b", @"c", nil];
    

    }

    return _quotes; }

  • (NSString *) randomQuote {

    return @"Some Quote"; }

@end"

hmm can i see your quote.h file please

thank you so much it is working now, for some reason it was because i had the property " readonly"