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

Error message crystal ball app

Xcode is complaining stating undeclared identifier _predictions. But I have declared it in the .h file. Any solutions would be much appreciated!

@implementation crystalball

-(NSArray *) predictions{

    if (_predictions == nil){
        _predictions = [[NSArray alloc]initWithObjects:@"It is certain",
                        @"It is decidedly so",
                        @"All signs say yes",
                        @"The stars are not aligned",
                        @"My reply is no",
                        @"You didn't focus enough", nil];

    }
    return _predictions;

}

  • (NSString*)randomPrediction{ int random = arc4random_uniform(self.predictions.count); return [self.predictions objectAtIndex:random]; }

@end

Amit Bijlani
Amit Bijlani
Treehouse Guest Teacher

After the @implementation add the following line:

@synthesize predictions = _predictions;

What's happening is that since the property is declared as readonly an instance variable is not being created for you. So we need to manually create one.

Sorry about this, I will add an addendum to the video to point that out.

1 Answer

Brilliant thanks for that Amit, seems to have done the trick!!