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

Peter Hearne
Peter Hearne
6,803 Points

code challenge

hello i am stuck on task 2 of 3 on the code challange on creating a custom class on the build a simple iphone app this is what im 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 have entered..

@implementation _quotes

- (NSArray *) quotes {
    if (_quotes == nil){
        quotes = [[NSArray alloc] initWithObjects:@"It is Certain",
                      @"It is Decidedly so",
                      @"All signs say YES!", nil];
    }
    return _quotes;
}

3 Answers

Amit Bijlani
STAFF
Amit Bijlani
Treehouse Guest Teacher

You are almost right except for one little issue. On the line after the if statement you missing an underscore prefix for the instance variable _quotes.

Peter Hearne
Peter Hearne
6,803 Points

i added the underscore prefix and its still not passing

Amit Bijlani
Amit Bijlani
Treehouse Guest Teacher

Noticed that you renamed the @implementation. Change it back what it was.

Peter Hearne
Peter Hearne
6,803 Points

it still doesnt seem to be working, this is what my code looks like now..

@implementation Quote

  • (NSArray *) quotes { if (_quotes == nil){ _quotes = [[NSArray alloc] initWithObjects:@"It is Certain", @"It is Decidedly so", @"All signs say YES!", nil]; } return _quotes; }