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 Readonly Attribute

Custom Class not working as shown in video on my end

after creating the custom class THCrystalBall. when doing the following line: self.crystalBall = [[THCrystalBall alloc] init]; the array is not being initialized. I have re-watched the vids and i have done everything as he has written the code. So basically the "getter" function is not executing. I added a line below the alloc init NSLog(@"predictions %@",self.crystalBall.predictions); this fires the getting which puts all the values into the array. I know because via debugger it finally went into that code where i had a breakpoint set. either i missed one step or something is wrong with the vid. please advise.

Stone Preston
Stone Preston
42,016 Points

can you post your getter for the property?

1 Answer

never mind. i found the problem

before:

// method returning random string from instance array for the class
- (NSString*) randomPrediciton{
    int random = arc4random_uniform(_predictions.count); <-- problem here instead of self. i had _predictions
    // return value from array with random index
    return [_predictions objectAtIndex:random];
}

after:

// method returning random string from instance array for the class
- (NSString*) randomPrediciton{
    int random = arc4random_uniform(self.predictions.count);
    // return value from array with random index
    return [_predictions objectAtIndex:random];
}