指示协议响应任何选择器

发布于 2024-09-30 22:41:11 字数 183 浏览 2 评论 0原文

在具有大量委托和方法转发的复杂库上。我收到很多关于主类的警告,说它可能不会响应选择器。

对象创建者返回:

- (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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别把无礼当个性 2024-10-07 22:41:11

有没有办法向 Obj-C 编译器指示协议响应任何选择器而不发出警告?

协议不响应选择器。对象响应选择器。协议的主要目的是产生您想要抑制的编译时警告。因此,当我说你所要求的事情无法完成时,你不会感到惊讶。

您可以通过将对象转换为纯 id 来抑制警告。

Is there a way to indicate to the Obj-C compiler that the protocol responds to any selector, without warnings ?

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文