我有一个 Timer 类和一个 ManualTimer 类,它们都声明了一个协议(protocol)。在 Timer.h 中,我有这个
@property (nonatomic, weak) id <TimerDelegate> delegate;
在 ManualTimer.h 中,我有这个
@property (weak, nonatomic) id <ManualTimerDelegate> delegate;
但是 xCode 给了我一个警告
property type id <ManualTimerDelegate> is incompatible with type id <TimerDelegate> inherited from parent class
的确,this 的答案之一所以问题说子类委托(delegate)必须与父类(super class)兼容,但没有说明我该怎么做。你可以解释吗? 我该如何解决这个问题?
最佳答案
当您声明 ManualTimerDelegate
协议(protocol)时,使其符合“父类(super class)”协议(protocol) (TimerDelegate
)。
@protocol ManualTimerDelegate < TimerDelegate >
@end
你的 TimerDelegate
应该是这样的:
@protocol TimerDelegate < NSObject >
@end
关于ios - 子类中的委托(delegate)声明与父类中的委托(delegate)不兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23328984/