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

Readonly Attribute Errors In First Build

I am approximately 3:50 into the Readonly Attribute tutorial and am stuck after running the application. I receive two compiler errors for my CrystalBall.m file:

  1. Method definition for 'randomPrediction' not found.
  2. Use of undeclared identifier 'randomPrediction'

Here is the code for my CrystalBall.m file:

   #import "LKCrystalBall.h"

   @implementation LKCrystalBall

   - (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",
           @"It is doubtful",
           @"Better not tell you now",
           @"Concentrate and ask again",
           @"Unable to answer now", nil];
       }
       return _predictions;

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

1 Answer

Never mind, figured it out. Looks like I had a curly brace misplaced. Program not compiles and runs correctly. Here is the updated code:

#import "LKCrystalBall.h"

@implementation LKCrystalBall

- (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",
        @"It is doubtful",
        @"Better not tell you now",
        @"Concentrate and ask again",
        @"Unable to answer now", nil];
    }
    return _predictions;
}

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

@end