-1

How to supress a warning on the line on Objective-C compiler?

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

NSObject has this method (as category). But compiler thinks that UIWebDocumentView doesn't. This is a compiller's issue. Is there any directive to suppress warnings on a block of the code?

The warning:

Receiver 'UIWebDocumentView' is a forward class and corresponding @interface may not exist

P.S. UIWebDocumentView is a private API - so can't use performSelector method tu supress the warning.

Dmitry
  • 14,306
  • 23
  • 105
  • 189

2 Answers2

4

Generally, you can ignore warnings for a single line of code like this:

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

replace -Warc-performSelector-leaks with the actual warning.

Since you didn't post the exact warning you have to figure out the -WarnLevel on your own.

Matthias Bauch
  • 89,811
  • 20
  • 225
  • 247
2

The easiest way to fix this is just to get the class a different way:

[NSClassFromString(@"UIWebDocumentView") jr_swizzleMethod:@selector(canPerformAction:withSender:) withMethod:@selector(myCanPerformAction:withSender:) error:nil]; // warning here
rob mayoff
  • 375,296
  • 67
  • 796
  • 848