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

quotes method not initializing and no idea why not

What is wrong here? I am being asked to allocate, initialize and return the quote array declared as a property in the the 'h' file.

// 'quote.h'

@interface Quote : NSObject

@property(strong,nonatomic) NSArray *quote;

- (NSString *) randomQuote;

@end


//-------------------------------------

// 'quote.m'

#import "Quote.h"

@implementation Quote

- (NSArray *) quotes{
  if (_quotes == nil){
    NSArray _quotes = [[NSArray alloc] initWithObjects:@"one", @"two", @"three", nil];
  }
  return _quotes;
}

- (NSString *) randomQuote {

    return @"Some Quote";
}

@end

Step 1 Screenshot: https://s3.amazonaws.com/justinmalone/treehouse/Screen+Shot+2014-09-16+at+3.58.24+PM.png">

Step 2 Screenshot: https://s3.amazonaws.com/justinmalone/treehouse/Screen+Shot+2014-09-16+at+4.00.18+PM.png

2 Answers

Chris Shaw
Chris Shaw
26,676 Points

Hi Justin,

You have NSArray at the start of your allocation line which doesn't need to be there as the instance variable _quotes will be assigned that type because of it's parent quotes.

_quotes = [[NSArray alloc] initWithObjects:@"one", @"two", @"three", nil];

Thank you very much, Test passing.

To add to Chris Upjohn's (correct) answer:

Make sure you double check everything for typos. In the code blocks you included within your forum post, I can see that the @property in the header file is defined as "quote" whereas you typed "quotes" in your implementation.

Additionally, within the screenshots you provided, you forgot one of the double-quotes when you were declaring your strings.

I also noticed that the issue Chris pointed out is not present in the screenshots. Overall, I think you just need to pay more attention to consistency and proper syntax.

Thanks for additional comments Alex. Walking away from my computer once every 20 hours could help with focusing and uncross my eyes.