动态转发:抑制未完成执行警告 [英] Dynamic forwarding: suppress Incomplete Implementation warning

查看:37
本文介绍了动态转发:抑制未完成执行警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类公开了一些方法,其实现由内部对象提供.

I have a class exposing some methods, whose implementation is provided by an inner object.

我使用前向调用在运行时将方法调用分派到内部对象,但 XCode 抱怨,因为它找不到已声明方法的实现.

I'm using forward invocation to dispatch at runtime the method calls to the inner object, but XCode is complaining since it cannot find an implementation of the declared methods.

我在 SO 上发现了一些其他类似的问题,但所有这些问题都通过设计更改得到了解决.

I found some other similar questions on SO, but all of them were solved with a design change.

我不想在这里讨论设计,但如果有人对此有任何建议,我有一个 open question on Code Review,更适合这类讨论.

I don't mean to have a discussion about the design here, but if anybody has some suggestion about it I have an open question on Code Review, which is more suitable for such kind of discussions.

我的问题是,是否存在关闭 XCode 中 Incomplete Implementation 警告的方法.

My question is here is whether a method to turn off the Incomplete Implementation warning in XCode exists.

推荐答案

您可以通过添加

  #pragma clang diagnostic ignored "-Wincomplete-implementation"

就在@implementation

希望能帮到你

编辑

在评论中被告知这对某人不起作用并找出原因是因为这是他们收到的不同警告后,我已经做了一些尝试并能够解决那里的问题,所以我以为我会更新这个答案以包含他们的答案,并且对于 GCC 也忽略.因此,对于 @Tony 的问题,以下应该有效

After being told in the comments that this didn't work for someone and finding out the reason was because it was a different warning they were getting I have done a bit of playing around and been able to solve there issue to so I thought I would update this answer to include theirs and for GCC ignores as well. So for the issue for @Tony the following should work

  #pragma clang diagnostic ignored "-Wprotocol"

对于任何想知道 GCC 编译器版本的人来说

For anyone wanting to know the GCC compiler version it is

  #pragma GCC diagnostic ignored "-Wprotocol"

  #pragma GCC diagnostic ignored "-Wincomplete-implementation"

我还要指出,所有这些诊断忽略也可以通过转至XCODE Project>在每个文件的基础上指定设置来完成.目标 >>构建阶段 >>编译源代码 并添加一个编译器标志,这样您只需添加 -WprotocolWincomplete-implementation 或您需要的任何编译器标志.

I will also make a point that all these diagnotstic ignores can also be done by specifying the setting on a per file basis by going to XCODE Project >> Target >> Build Phases >> Compile Sources and adding a compiler-flag so you would just add -Wprotocol or Wincomplete-implementation or whatever compiler-flag you needed.

希望此更新对所有人有所帮助,如果再需要我会更新我的答案以包括在内.

Hope this update helps all if anymore need I will update my answer to include.

编辑 2

我正在对此进行更多的挖掘,结果发现了 Clang Compliler User's Manual 所以我认为这对在这方面仍然有问题的任何人都会很有趣和有帮助.

I was doing a bit more digging around about this an came across the Clang Compliler User's Manual so I thought that this would be interesting and helpful to anyone having issues around this area still.

我还发现了另一种可以使用这些 #pragma diagnostic ignores 的方法,那就是你可以 pushpop 它们,所以如果您只想忽略文件的特定部分而不是全部,那么您可以执行以下操作

I have also found another way that you can use these #pragma diagnostic ignores and that is you can push and pop them so if you wanted to just ignore a particular section of the file and not all of it then you could do the following

    #pragma clang diagnostic push
    #pragma clang diagnostic ignored "-Wmultichar"

    // And pop the warning is gone.
    char b = 'fa';

    #pragma clang diagnostic pop

请记住,所有这些 #pragma 编译忽略也可以与 GCC 一起使用,因此上述内容将

Remember that all these #pragma compile ignores can be used with GCC as well so the above would

    #pragma GCC diagnostic push
    #pragma GCC diagnostic ignored "-Wmultichar"

    // And pop the warning is gone.
    char b = 'fa';

    #pragma GCC diagnostic pop

pushpop 似乎适用于我迄今为止尝试过的所有 诊断忽略.

The push and pop seem to work with all the diagnostic ignores I have tried so far.

另一个是

    #pragma clang diagnostic ignored "UnresolvedMessage"
    #pragma GCC diagnostic ignored "UnresolvedMessage"

抑制未使用变量的方法是

The one for suppressing unused variables is

    #pragma clang diagnostic push
    #pragma clang diagnostic ignored "-Wunused-variable"
        NSString *myUnusedVariable;
    #pragma clang diagnostic pop

和 GCC 版本是

    #pragma GCC diagnostic push
    #pragma GCC diagnostic ignored "-Wunused-variable"
        NSString *myUnusedVariable;
    #pragma GCC diagnostic pop

忽略来自unavailableInDeploymentTarget 的警告的更多信息

A few more for ignoring warnings from unavailableInDeploymentTarget

    #pragma clang diagnostic push
    #pragma ide diagnostic ignored "UnavailableInDeploymentTarget"
        leftEdge.barTintColor = rightEdge.barTintColor = self.toolbar.barTintColor;
    #pragma clang diagnostic pop

和 performSelector 泄漏

and performSelector leaks

    #pragma clang diagnostic push
    #pragma clang diagnostic ignored "-Warc-performSelector-leaks"
    [target performSelector:cancelAction withObject:origin];
    #pragma clang diagnostic pop

和弃用的声明

    #pragma clang diagnostic push
    #pragma clang diagnostic ignored "-Wdeprecated-declarations"
        button = [[UIBarButtonItem alloc] initWithTitle:buttonTitle style:UIBarButtonItemStyleBordered target:self action:@selector(customButtonPressed:)];
    #pragma clang diagnostic pop

感谢 DanSkeel,您可以在此处找到完整列表

这篇关于动态转发:抑制未完成执行警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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