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

Liang Jin
Liang Jin
1,080 Points

When 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
Neil Shweky
5,022 Points

I think I may have figured out your problem.

  1. If you change _predictions to self.predictions (since it is a property of 'self'), everything checks out.
  2. 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
Liang Jin
1,080 Points

y, just watched the following videos, it turns out that creating a _predictions NSArray under the interface would work. Thanks!