在Xcode中抑制未找到的类方法警告 [英] Suppressing Class Method Not Found Warnings in Xcode

查看:56
本文介绍了在Xcode中抑制未找到的类方法警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个其方法在运行时确定的类,如我的问题此处所示。效果很好,但是现在我收到了很多警告,看起来像下面的代码:

I have a class whose methods are determined at runtime, as indicated in my question here. This works great, but now I have a bunch of warnings that look like the following littering my code:

Class method '+objectIsNotNil:' not found (return type defaults to 'id')

这些警告实际上并没有影响在构建过程中,它们非常烦人,因此很难发现相关警告。有什么方法可以禁用它们,但只能用于 Assert 类(也许是某种宏)吗?如果无法做到这一点,那么是否有某种方法可以在整个构建过程中将其关闭?

While these warnings don't actually affect the build process, they're very annoying and make it harder to spot relevant warnings. Is there some way to disable them, but only for the Assert class (maybe some kind of macro)? If this isn't possible, then is there some way to turn them off for the entire build?

推荐答案

一种选择是使用performSelector:withObject:而不是直接方法调用。
因此,而不是:

One alternative would be to use performSelector:withObject: instead of the direct method call. So instead of:

[Assert objectIsNotNil:object];

您可能会:

[Assert performSelector:@selector(objectIsNotNil:) withObject:object];

它看起来不太好看,但是会删除警告。此外,此模式适用于所需的任何选择器。为了使事情看起来更好一点,您可以通过以下方式使用宏:

It does not look quite as nice but it will remove the warnings. Furthermore, this pattern will work for any selector you want. To make things look a little better you could use macros in the following way:

#define ASSERT_PRECONDITION(sel, obj)  [Assert performSelector:@selector(sel) withObject:obj]

这样,您的断言将如下所示: / p>

This way your assert would look like this:

ASSERT_PRECONDITION(objectIsNotNil:, object);

这篇关于在Xcode中抑制未找到的类方法警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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