Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Build a Simple iPhone App (iOS7) Refactoring into a Model Creating a Custom Class

Am i wrong? quiz

it asks you to set the quote to 3 quotes only if _quotes is 'nil', i don't understand why this is wrong...

import "Quote.h"

@implementation Quote

  • (NSString *) randomQuote {

    return @"Some Quote"; }

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


1 Answer

Robert Bojor
Robert Bojor
Courses Plus Student 29,439 Points

First you need to add the @property in the header file:

@property (strong, nonatomic) NSArray *quotes;

Next you need to move to the implementation file and create the quotes method that returns the array...

- (NSArray *)quotes {
    if (_quotes == nil) {
    _quotes = [[NSArray alloc] initWithObjects:@"Quote 1", @"Quote 2", @"Quote 3", nil];
  return _quotes;

and last, change the randomQuote in the implementation file to return one of the quotes randomly using arc4random_uniform() and passing it [_quotes count] as a max rand.

- (NSString *) randomQuote {
    return [_quotes objectAtIndex:arc4random_uniform([_quotes count])];