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 trialLiang Jin
1,080 PointsWhen set the array property to be ready only, error occurred in .m file
After setting the property of predictions in THCrystallBall.h to have readonly attributes : @property (strong, nonatomic, readonly) NSArray *predictions;
Errors occurred in the THCrystallBall.m file :
import "THCrystallBall.h"
@implementation THCrystallBall
-(NSArray *) predictions{ if (_predictions == nil){ _predictions = [[NSArray alloc] initWithObjects:@"it is certain", @"aa",@"bb", @"cc",@"dd",@"ee",@"ff",nil]; } return _predictions; }
for "_predictions" error message:"Semantic Issue, use of undeclared identifier '_predictions'"
1 Answer
Neil Shweky
5,022 PointsI think I may have figured out your problem.
- If you change _predictions to self.predictions (since it is a property of 'self'), everything checks out.
- Setting it as 'readonly' means that you cannot set a value to it, so allocating and initializing the array would cause an error.
Liang Jin
1,080 PointsLiang Jin
1,080 Pointsy, just watched the following videos, it turns out that creating a _predictions NSArray under the interface would work. Thanks!