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

Esma Goktekin
Esma Goktekin
3,870 Points

Switch to the implementation file and implement a 'quotes' method which will allocate and initialize the _quotes instanc

I don't know what is wrong with my answer. Any help will be greatly appreciated. -(NSArray *) quotes{ if(_quotes == nil) { _quotes = [[NSArray alloc] initWithObjects:@"a",@"d",@"c",nil];} return _quotes; }

Esma Goktekin
Esma Goktekin
3,870 Points

Stage 4 Refactoring into a Model

Pierre Thalamy
Pierre Thalamy
4,494 Points

Please refer to the Markdown Cheatsheet on how to format your code when posting on the forum, it makes it much easier to read it! ;)

(NSArray *) quotes { 
    if (_quotes == nil) { 
        _quotes = [[NSArray alloc] initWithObjects:@"a",@"d",@"c",nil];
    } 
return _quotes; 
}

Let me have a look at this.

2 Answers

Pierre Thalamy
Pierre Thalamy
4,494 Points

I have just done it once again to check and this is the correct answer:

- (NSArray *) quotes {

  if (_quotes == nil) {
    _quotes = [[NSArray alloc] initWithObjects:@"1", @"2", @"3", nil];
  }

    return _quotes;
}

Which is exactly the same as yours, but it seems that you forgot the - before the method implementation. What that the problem?

- (NSArray *) quotes {

  if (_quotes == nil) {
    _quotes = [[NSArray alloc] initWithObjects:@"foo", @"bar", @"car", nil];
  }

    return _quotes;
}

this was my answer and its not working. Did I miss something? Looking at this forum it looks like I did it right. It's saying I'm wrong.

Nevermind, I had messed up calling my property.