为什么要将NSObject的协议绑定到协议实现 [英] Why tack a protocol of NSObject to a protocol implementation

查看:100
本文介绍了为什么要将NSObject的协议绑定到协议实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到一些类似于下面的代码:

I have been seeing some code around that resembles the following:

@protocol MyProtocol <NSObject>
// write some methods.
@end

MyProtocol是否符合NSObject协议有什么特别的原因?这不是那么多余的,如果你做一些事情,如:

Is there any particular reason why MyProtocol conforms to the NSObject protocol? Isn't that rather redundant in that if you do something such as:

id <MyProtocol> foo; // foo here conforms to NSObject AND MyProtocol?

只是好奇这是什么逻辑。

Just curious what the logic is.

推荐答案

我很确定,你会这样做的原因是添加NSObject成员(比如像retain和release)到你的协议。技术上你仍然可以发送这些消息,但你会得到一个编译器警告没有它。

I'm pretty sure the reason you would do this is to add the NSObject members (say like retain and release) to your protocol. Technically you can still send those messages anyways but you will get a compiler warning without it.

这篇关于为什么要将NSObject的协议绑定到协议实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆