在Objective-C中,我想在类synthesized (assigned)
中的Compass
类中设置B
属性
这是我的代码......
for(Compass * ind in CompassList){
if([[(Compass*)ind showAnalog] isEqualToString:str]){
ind.analogValue=11.0;
}
}
但是,我收到了这个错误......
Request for member analogValue in something not a structure or union.
我设法通过使用自己的setter并将其称为[ind updateValue:11.0];
来避免此错误。但是,当我稍后在另一个类中调用合成的getter像[(Compass*)currentDevice analogValue];
时,我得到以下异常......
'NSInvalidArgumentException': [Compass digitalValue]: unrecognized selector sent to instance 0x613ca20
有人可以帮我理解我应该怎么做。
答案 0 :(得分:0)
您正快速将indicatorList枚举为类型Indicator
,然后您下面的一行将其转换为Compass
。如果这不是拼写错误并且所有值都是Compass
类型,那么将代码更改为
for(Compass * compass in indicatorList){
if([[compass showAnalog] isEqualToString:str]){
compass.analogValue=11.0;
}
}
现在针对您的实际问题,您没有发布与该问题相关的代码。我猜测原因来自showAnalog
调用的一些代码,而这些代码又调用了[(Compass*)currentDevice analogValue];
。这可能都与错误的投射有关,或者没有完全实现Compass
类。