property x not found on object of type y

ぐ巨炮叔叔 提交于 2020-01-07 02:16:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!