问题
Newbie here, working on a programmable calculator.
In the interface of the model class CalculatorBrain
, I declare
@property (nonatomic, strong) NSMutableArray *whatHappenedSinceLastClear;
Then in the implementation I also declare
-(NSMutableArray *)whatHappenedSinceLastClear
{
if(!_whatHappenedSinceLastClear) _whatHappenedSinceLastClear = [[NSMutableArray alloc] init];
return _whatHappenedSinceLastClear;
}
and then
-(double)runProgram:(id)whatHappenedSinceLastClear
{
NSMutableArray *mutableCopyOfWhatHappenedSinceLastClear;
if ([program isKindOfClass:[NSArray class]]) {
mutableCopyOfWhatHappenedSinceLastClear = [whatHappenedSinceLastClear mutableCopy];
}
return [self popOffProgramStack:mutableCopyOfWhatHappenedSinceLastClear];
}
But in the ViewController, when I declare
-(IBAction)testPressed:(id)sender
{
CalculatorBrain *brain = self.brain;
brain = [[CalculatorBrain alloc] init];
NSMutableArray *program = brain.whatHappenedSinceLastClear;
[brain runProgram:program];
}
in the line NSMutableArray *program = brain.whatHappenedSinceLastClear;
I get a message that says "property 'whatHappenedSinceLastClear' not found on object of type 'CalculatorBrain *'.
What am I doing wrong?
回答1:
Try this: replace:
NSMutableArray *program = brain.whatHappenedSinceLastClear;
by
NSMutableArray *program = [brain whatHappenedSinceLastClear];
and in brain.h
-(NSMutableArray *)whatHappenedSinceLastClear;
this should work.
来源:https://stackoverflow.com/questions/11752983/property-x-not-found-on-object-of-type-y