如何初始化 NSObject<协议>指针,以便它响应委托 SEL?协议>
我的类定义中有这样的内容:
NSObject<SomeProtocol> *dataDelegate;
我有自定义的 -(id)init
方法,我应该在其中初始化这个 NSObject
。如果我希望它响应 SomeProtocol
中的选择器,我该怎么做?
I have such thing in my class definition:
NSObject<SomeProtocol> *dataDelegate;
I have custom -(id)init
method in which I should init this NSObject
. How do I do it if I want it to respond selectors from SomeProtocol
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您有一个声明为实现
SomeProtocol
的类,那么您只需执行以下操作:在实现中:
If you have a class declared to implement
SomeProtocol
, then you'd just do:And in the implementation:
您只需要创建一个实现该协议的类的实例。
You just need to create an instance of a class that implements the protocol.