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

What is wrong with my code in this challenge. ? Task 2 Many thanks.

import "Quote.h"

@implementation Quote

  • (NSArray*) quotes { if (_quotes == nil) { _quotes = [[NSArray alloc] initWithObjects:@"This is hard",@"That is ok", nil]; }

  • (NSString *) randomQuote {

    return @"Some Quote"; }

@end

1 Answer

Peter Simpson
PLUS
Peter Simpson
Courses Plus Student 15,526 Points

I'm not quite sure what the question is asking for, but I think your code should look like this? '''

  • (NSArray *) quotes {

if (_quotes == nil) _quotes =[[NSArray alloc]initWithObjects: @"This is hard", @"That is ok", nil]; return _quotes; }

'''

Mike Baxter
Mike Baxter
4,442 Points

I recommend giving the OP code that scopes the if statement in curly braces to help avoid further errors.

I agree with Peter's answer. Peter's code looks like this with those:

- (NSArray *) quotes {

    if (_quotes == nil) {
       _quotes = [[NSArray alloc] initWithObjects: @"This is hard", @"That is ok", nil];
   }

   return _quotes;
}

Make sure _quotes is listed in your Quote.h file too, Keith. Cheers!

Thanks for the help, Gents! Got me past the quiz. Best! K