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
Jonathan Fernandez
8,325 PointsExtra Credit: Modify the CrystalBall class to work without the @property predictions.
So I'm guessing that the challenge is asking us to use the old setter and getter methods rather than @property. So I had commented out my property code (and to my surprise it works but I'm guessing thats cause we set an instance variable in the video)
Anyway back to the code I had then went to try and use a setter and getter method. I had followed the format from the intro video to objective C back in basics. For some reason though the complier doesn't like my code. Can anyone tell me what syntax I'm doing wrong or what is wrong with my getter method? The main problem is the .m file for getter.
Code of .h <p> @interface JWFTheCrystalBall : NSObject { NSArray *_predictions; NSArray *_colors; }
-(void)setPreditions:(NSArray *) predictions; //setter -(NSArray *) predictions; //getter
//@property (strong, nonatomic, readonly) NSArray *predictions; //Commented out property. </p> Code of .m <p> -(void)setPreditions:(NSArray *)predictions{ //Setter if (_predictions == nil) { _predictions = [[NSArray alloc] initWithObjects: @"It is Certain", @"It is Decidely 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]; }
-(NSArray *) predictions{ //getter
return _predictions;
}
/*- (NSArray *) predictions { //Commented out original code for setter and getter meathods.
if (_predictions == nil) {
_predictions = [[NSArray alloc] initWithObjects:
@"It is Certain",
@"It is Decidely 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;
}
*/ </p>
Any feedback will be greatly appreciated!! : )
2 Answers
Misha Shaposhnikov
8,718 PointsYou seem to have an asterisk and backslash before the dash of the getter. Could that be a problem?
Jonathan Fernandez
8,325 PointsThanks for the feedback. I was actually able to do it and get the app to run. The thing was I was missing a { so the scoping was kinda messed up. Although a new problem with finally setting the getter and setter methods is that after I click the button, the text ends up disappearing.. : /. It's quite strange and after a bit of online reading I think it has something to do with the instance _variables and arc but I can't really tell for sure..