指示协议响应任何选择器
在具有大量委托和方法转发的复杂库上。我收到很多关于主类的警告,说它可能不会响应选择器。
对象创建者返回:
- (id<MainProtocol>) foo;
有没有办法向 Obj-C 编译器指示协议响应任何选择器,而不发出警告?
谢谢,JD
On a complex library with lots of delegates and method forwarding. I get a lot of warnings on the main class saying it might not respond to the selector.
The object creator returns:
- (id<MainProtocol>) foo;
Is there a way to indicate to the Obj-C compiler that the protocol responds to any selector, without warnings ?
Thanks, JD
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
协议不响应选择器。对象响应选择器。协议的主要目的是产生您想要抑制的编译时警告。因此,当我说你所要求的事情无法完成时,你不会感到惊讶。
您可以通过将对象转换为纯
id
来抑制警告。Protocols don't respond to selectors. Objects respond to selectors. The main purpose of a protocol is to produce those compile time warnings that you want to suppress. So you will not be surprised when I say what you ask for can't be done.
You can suppress the warnings by casting the object to a plain
id
.