2012-11-08 38 views
-1

如何在Objective-C编译器上禁用线上的警告?如何抑制Objective-C编译器上的警告线?

... 
[[UIWebDocumentView class] jr_swizzleMethod:@selector(canPerformAction:withSender:) withMethod:@selector(myCanPerformAction:withSender:) error:nil]; // warning here 
... 

NSObject有此方法(作为类别)。但编译器认为UIWebDocumentView没有。这是一个竞争者的问题。是否有任何指令来压制代码块的警告?

警告:

接收机 'UIWebDocumentView' 是一个正向类和对应 @interface可能不存在

P.S. UIWebDocumentView是一个私有API - 因此不能使用performSelector方法禁止警告。

+0

请你的问题并添加行和**确切的警告文字**。 –

+0

我想找到一种方法来抑制任何警告。 – Dmitry

+1

[@selector - 带多个参数?](http://stackoverflow.com/questions/2297613/selector-with-multiple-arguments) –

回答

2

解决这个问题的最简单的方法就是让类以不同的方式:

[NSClassFromString(@"UIWebDocumentView") jr_swizzleMethod:@selector(canPerformAction:withSender:) withMethod:@selector(myCanPerformAction:withSender:) error:nil]; // warning here 
2

一般来说,你可以忽略警告,代码类似这样一行:

#pragma clang diagnostic push 
#pragma clang diagnostic ignored "-Warc-performSelector-leaks" 
[foo bar]; 
#pragma clang diagnostic pop   

与实际警告更换-Warc-performSelector-leaks

既然你没有发布确切的警告,你必须自己找出-WarnLevel。

+0

我已将实际的警告添加到问题中。 – Dmitry

+0

如何为它找到正确的“-W ...”字符串? – Dmitry

+0

警告是:'Receiver'UIWebDocumentView'是一个前向类,相应的@interface可能不存在.' – Dmitry