在类型y的对象上找不到属性x [英] property x not found on object of type y
本文介绍了在类型y的对象上找不到属性x的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里的新手,正在使用可编程计算器.
Newbie here, working on a programmable calculator.
在模型类CalculatorBrain
的接口中,我声明
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;
}
然后
-(double)runProgram:(id)whatHappenedSinceLastClear
{
NSMutableArray *mutableCopyOfWhatHappenedSinceLastClear;
if ([program isKindOfClass:[NSArray class]]) {
mutableCopyOfWhatHappenedSinceLastClear = [whatHappenedSinceLastClear mutableCopy];
}
return [self popOffProgramStack:mutableCopyOfWhatHappenedSinceLastClear];
}
但是在ViewController中,当我声明
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];
}
在行NSMutableArray *program = brain.whatHappenedSinceLastClear;
中,我收到一条消息,指出在'CalculatorBrain *'类型的对象上找不到属性'whatHappenedSinceLastClear'.
in the line NSMutableArray *program = brain.whatHappenedSinceLastClear;
I get a message that says "property 'whatHappenedSinceLastClear' not found on object of type 'CalculatorBrain *'.
我在做什么错了?
推荐答案
尝试一下: 替换:
NSMutableArray *program = brain.whatHappenedSinceLastClear;
作者
NSMutableArray *program = [brain whatHappenedSinceLastClear];
和在大脑中.h
-(NSMutableArray *)whatHappenedSinceLastClear;
这应该有效.
这篇关于在类型y的对象上找不到属性x的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文