动态转发:抑制“实施不完整"警告 [英] Dynamic forwarding: suppress Incomplete Implementation warning

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

问题描述

我有一个暴露一些方法的类,其实现由内部对象提供.

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.

我并不是要在这里讨论设计,但是如果有人对此有任何建议,我会提供一个

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"

我还要指出,所有这些diagnotstic ignores也可以通过按每个文件指定设置来完成,方法是转到XCODE Project >> Target >> Build Phases >> Compile Sources并添加一个编译器标志,因此您只需添加-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用户手册因此,我认为这对于仍然在该区域有问题的任何人都将是有趣且有帮助的.

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似乎可以与到目前为止我尝试过的所有diagnostic ignores一起使用.

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,您可以在此处找到整个列表

Thanks to DanSkeel you can find the entire list here

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

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