如何忽略“没有可见的@interface for X声明选择器”? [英] How to ignore "No visible @interface for X declares the selector"?

查看:225
本文介绍了如何忽略“没有可见的@interface for X声明选择器”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ARC之前,我有一个X可能无法响应xxx警告,这是一个非常无害的警告,不会阻止它编译。现在,我正在尝试将我的项目转换为ARC,并且我有一个没有可见的@interface for X声明选择器xxx错误,这会阻止它编译。<​​/ p>

我确切地知道我在做什么,为什么警告在那里,我可以告诉你程序是正确的。以前,编译器编译它没有问题,现在不应该停止编译。



类X的接口确实没有声明那个选择器,但X是使用 forwardInvocation:(这是关于Objective-C的美妙事物之一)动态处理发送给它的任何选择器的任何消息的类,因此它的接口不可能声明可以在其上调用的所有选择器。并且选择器在某处声明,而不是在X上。

解决方案


我确切地知道我在做什么,为什么警告在那里,我可以告诉你程序是正确的。


好的 - 只需使用 objc_msgSend 等。直接如果你想编译器的工作。


类X的接口确实没有声明那个选择器,但X是一个类使用forwardInvocation动态处理发送给它的任何选择器的任何消息:(这是关于Objective-C的美妙事物之一),因此它的接口不可能声明可以在其上调用的所有选择器。并且选择器被声明在某个地方,而不是在X上。


如果声明太繁琐但在传递中使用时不够乏味似乎与你的程序对选择器的使用相矛盾......听起来像是生成代码的危险区域,有很大的人为干预。



也许你应该考虑声明一个协议,这样编译器就可以在至少为您正确设置消息调用 - 如果您更改或破坏某些内容,它有机会适应或通知您。


Before ARC, I had an "X may not respond to xxx" warning, which is a pretty harmless warning which does not prevent it from compiling. Now, I am trying to convert my project to ARC, and I have an "No visible @interface for X declares the selector xxx" error, which prevents it from compiling.

I know exactly what I am doing, and why the warning was there, and I can tell you that the program is correct. Previously, the compiler compiled it with no problem, and should not now stop it from compiling.

It is true that class X's interface does not declare that selector, but X is a class that dynamically handles any message with any selector sent to it, using forwardInvocation: (that is one of the beautiful things about Objective-C), so its interface cannot possibly declare all the selectors that can be called on it. And the selector is declared somewhere, just not on X.

解决方案

I know exactly what I am doing, and why the warning was there, and I can tell you that the program is correct.

OK -- Just use objc_msgSend et al. directly if you want to do the compiler's work.

It is true that class X's interface does not declare that selector, but X is a class that dynamically handles any message with any selector sent to it, using forwardInvocation: (that is one of the beautiful things about Objective-C), so its interface cannot possibly declare all the selectors that can be called on it. And the selector is declared somewhere, just not on X.

If it's too tedious to declare but not tedious enough to use in messaging that seems to contradict your program's use of the selector… Sounds like the dangerous territory of generated code with significant human intervention.

Perhaps you should consider declaring a protocol so the compiler can at least set the message calls up correctly for you -- and if you change or break something, it has a chance to adapt or notify you.

这篇关于如何忽略“没有可见的@interface for X声明选择器”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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