如何在特定行上禁用 xcode 中的警告?
我接到一个像这样的电话 [Class method] 并警告说 Class 可能不会 响应“方法”消息。
“方法”消息确实不存在,但我的代码使用未知消息捕获 (使用forwardingTargetForSelector)所以它会运行良好并且它被构建为以这种方式运行。 我怎样才能隐藏这个恼人的警告?
I've got a call like this [Class method] and a warning saying that Class may not
respond to "method" message.
The "method" message does not indeed exist but my code use unknown message catching
(using forwardingTargetForSelector) so it will run fine and it is build to run that way.
How can I hide this annoying warning ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您打算向对象发送可能未实现的消息,并且知道将捕获失败,则应该使用调用:
这更直接地声明您正在调用可能不存在的方法的意图,并且你对此很满意。这是比抑制警告或伪造方法更清晰的方法。
If you intend to send a possibly-unimplemented message to an object, and you know that you're going to catch failures, you should use the invocation:
That declares your intent more directly that you are calling a method that may not exist, and you're cool with that. This is a more clear way to do it than to suppress the warning or fake out the method.
您可以定义一个声明该方法的类别。在编译时将定义置于范围内可以避免出现警告。像这样的东西
You could define a category that declares that method. Having the definition in scope at the time of compilation would avoid the warning. Something like