xcode 动态转发:抑制未完成执行警告
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14444203/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Dynamic forwarding: suppress Incomplete Implementation warning
提问by Gabriele Petronella
I have a class exposing some methods, whose implementation is provided by an inner object.
我有一个类公开一些方法,其实现由内部对象提供。
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.
我正在使用前向调用在运行时将方法调用分派到内部对象,但 XCode 正在抱怨,因为它找不到已声明方法的实现。
I found some other similar questions on SO, but all of them were solved with a design change.
我在 SO 上发现了其他一些类似的问题,但所有这些问题都通过设计更改得到了解决。
I don't mean to have a discussion about the design here, but if anybody has some suggestion about it I have an open questionon Code Review, which is more suitable for such kind of discussions.
我并不是要在这里讨论设计,但是如果有人对此有任何建议,我有一个关于 Code Review的未决问题,它更适合此类讨论。
My question is here is whether a method to turn off the Incomplete Implementation
warning in XCode exists.
我的问题是这里是否Incomplete Implementation
存在关闭XCode 中警告的方法。
回答by Popeye
You can suppress Incomplete Implementation
warnings by adding
您可以Incomplete Implementation
通过添加来抑制警告
#pragma clang diagnostic ignored "-Wincomplete-implementation"
just above the @implementation
就在上面 @implementation
Hope this helps
希望这可以帮助
EDIT
编辑
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
在评论中被告知这对某人不起作用并找出原因是因为这是他们收到的不同警告我已经做了一些尝试并且能够解决那里的问题所以我想我会更新此答案以包括他们的和GCC
忽略的答案。所以对于以下问题@Tony
应该有效
#pragma clang diagnostic ignored "-Wprotocol"
For anyone wanting to know the GCC
compiler version it is
对于任何想知道GCC
编译器版本的人来说,它是
#pragma GCC diagnostic ignored "-Wprotocol"
#pragma GCC diagnostic ignored "-Wincomplete-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.
我也提出一个观点,所有这些diagnotstic ignores
也可以通过将指定的每个文件的基础设定完成XCODE Project >> Target >> Build Phases >> Compile Sources
并添加编译标志,这样你就只需要添加-Wprotocol
或者Wincomplete-implementation
或者你需要的任何编译器标志。
Hope this update helps all if anymore need I will update my answer to include.
希望此更新可以帮助所有人,如果再需要我会更新我的答案以包括在内。
EDIT 2
编辑 2
I was doing a bit more digging around about this an came across the Clang Compliler User's Manualso I thought that this would be interesting and helpful to anyone having issues around this area still.
我正在对此进行更多的挖掘,并偶然发现了Clang Compliler 用户手册,所以我认为这对在这方面仍然有问题的任何人都会很有趣和有帮助。
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 diagnostic ignores
,那就是你可以push
和pop
它们,所以如果你只想忽略文件的特定部分而不是全部,那么你可以执行以下操作
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmultichar"
// And pop the warning is gone.
char b = 'fa';
#pragma clang diagnostic pop
Remember that all these #pragma
compile ignores can be used with GCC
as well so the above would
请记住,所有这些#pragma
编译忽略也可以与GCC
上面一起使用
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmultichar"
// And pop the warning is gone.
char b = 'fa';
#pragma GCC diagnostic pop
The push
and pop
seem to work with all the diagnostic ignores
I have tried so far.
在push
和pop
似乎所有的工作,diagnostic ignores
到目前为止,我都试过了。
Another one is
另一个是
#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
and the GCC version being
和 GCC 版本是
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable"
NSString *myUnusedVariable;
#pragma GCC diagnostic pop
A few more for ignoring warnings from unavailableInDeploymentTarget
还有一些用于忽略来自unavailableInDeploymentTarget 的警告
#pragma clang diagnostic push
#pragma ide diagnostic ignored "UnavailableInDeploymentTarget"
leftEdge.barTintColor = rightEdge.barTintColor = self.toolbar.barTintColor;
#pragma clang diagnostic pop
and performSelector leaks
和 performSelector 泄漏
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[target performSelector:cancelAction withObject:origin];
#pragma clang diagnostic pop
and deprecated declarations
和弃用的声明
#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
Thanks to DanSkeel
you can find the entire list here
回答by Martin R
You can declare the methods in a class category interface:
您可以在类类别接口中声明方法:
@interface MyClass (ForwardedMethods)
- (void)doSomething;
@end
(without an implementation for the category). Then Xcode will not complain about "incomplete implementation" anymore.
(没有该类别的实现)。这样 Xcode 就不会再抱怨“不完整的实现”了。