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

Peter Hearne
Peter Hearne
6,803 Points

help

i am wondering if anyone else can help with this question

What is the question?

7 Answers

Stone Preston
Stone Preston
42,016 Points

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
Stone Preston
Stone Preston
42,016 Points

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;
}
Stone Preston
Stone Preston
42,016 Points

here is the .h file

@interface Quote : NSObject

// Add property here

@property (nonatomic, strong) NSArray *quotes;

- (NSString *) randomQuote;

@end
Peter Hearne
Peter Hearne
6,803 Points

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; }
Peter Hearne
Peter Hearne
6,803 Points

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"

Peter Hearne
Peter Hearne
6,803 Points

hmm can i see your quote.h file please

Peter Hearne
Peter Hearne
6,803 Points

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