【发布时间】:2018-07-11 19:08:09
【问题描述】:
对象的类接口声称对其实例变量之一的访问器返回“float”类型的数据。但是,当我尝试编译脚本以访问此变量时,编译器会抛出以下错误:“使用不兼容类型 'void' 的表达式初始化 'float'。” 实现代码是专有的,对我隐藏。最后一条数据是,在单步执行调试器时,调试器能够访问该方法并坚持返回的值是“float!”类型。
方法是否可以返回与接口中描述的数据类型不同的数据类型?我怎样才能找出这个方法真正返回什么?关于为什么编译器、调试器和头文件似乎不同意的任何建议?
在对象的头文件中,您可以看到接口声明访问器返回“float”:
@interface SBPulseTag : SBTag {
@private
float start,end;
enum PulseTypeEnum pulseType;
}
- (float)start;
- (float)end;
- (void)setStart:(float)val;
- (void)setEnd:(float)val;
@end
在我自己的代码中,我有一个通过 'PulseTag's 的 NSArray 枚举的方法,就像这样。
-(WaveformSegment *) WaveformSegmentTest:(int)myInput {
// <... Some overlying code...>
SBPulseTag *tag; // Declare an object to receive each object in the array
while(tag = [enumerator nextObject]) { // Loop through the array
int tmp = [tag start]; // Initializing 'float' with an expression of incompatible type 'void.'
}
最后,XCode 调试器可以清楚地访问 [tag start] 并将其读取为浮点数。这是 XCode 中调试器输出的快照:
有什么想法吗?我很困惑。
【问题讨论】:
标签: objective-c interface accessor custom-data-type