0
我创建了一个协议和一个类来使用该协议。警告 - 在协议中找不到发布
JSTest.h文件=
@protocol JSTestDelegate
@end
@interface JSTest : NSObject {
id<JSTestDelegate> delegate;
}
@property (nonatomic, retain) id<JSTestDelegate> delegate;
- (id)initWithDelegate:(id<JSTestDelegate>)del;
@end
JSTest.m文件=
我的问题是 - 在dealloc方法中,
[delegate release]
给我一个警告
-release not found in protocol(s)
我无法确定原因。我的代码不应该失败,因为委托将始终是NSObject的一个子类。但是,我有不好的经验,警告我不理解警告出现的原因而忽视。
的后续问题,那么:这是否有什么优势声明属性NSObject的 *和离开继承了协议? –
2010-11-09 16:02:42
工作。谢谢pgb。 – Sreejit 2010-11-09 16:02:57
@ w.m除了NSObject之外,Cocoa/Objective-C还有一个重要的基类:NSProxy(它也符合NSObject协议)。指定NSObject *不必要地限制NSProxy对象与API一起使用。当他们的意思是“任何对象”时,绝大多数Cocoa API使用'id',而不是'NSObject *'。 'id '模式只是现有模式的延续。 –
kperryua
2010-11-09 16:24:35