我在尝试调用方法时遇到错误。
方法
- (void)setSpeed:(GLKVector2)newSpeed{ //Error message (see title) points to here
self.speed = GLKVector2Make(newSpeed.x, newSpeed.y);
}
电话
[self setSpeed:GLKVector2Make(0, 0)];
有什么想法吗?
答案 0 :(得分:9)
尝试写
_speed = GLKVector2Make(newSpeed.x, newSpeed.y);
或
speed = GLKVector2Make(newSpeed.x, newSpeed.y);
而不是
self.speed = GLKVector2Make(newSpeed.x, newSpeed.y);
答案 1 :(得分:4)
self.speed=
使用为其选择的任何访问器设置speed
属性。名为“speed”的属性的setter的默认名称为setSpeed:
。这是你正在使用的方法,它只是一遍又一遍地自我调用,永不停止。您想直接设置实例变量(如果您只有@property
声明并且没有明确的@synthesize
,那么这将是_speed
)。