Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable warning in xcode on specific line?

I've got a call like this [Class method] and a warning saying that Class may not respond to "method" message.

The "method" message does not indeed exist but my code use unknown message catching (using forwardingTargetForSelector) so it will run fine and it is build to run that way. How can I hide this annoying warning ?

like image 884
CodeFlakes Avatar asked Sep 25 '09 16:09

CodeFlakes


2 Answers

If you intend to send a possibly-unimplemented message to an object, and you know that you're going to catch failures, you should use the invocation:

id myClone = [anObject performSelector:@selector(copy)];

That declares your intent more directly that you are calling a method that may not exist, and you're cool with that. This is a more clear way to do it than to suppress the warning or fake out the method.

like image 66
cdespinosa Avatar answered Oct 12 '22 10:10

cdespinosa


You could define a category that declares that method. Having the definition in scope at the time of compilation would avoid the warning. Something like

@interface MyClass (ShutUpTheCompilerMethods)
- (void)method;
@end

...

[MyClass method] //no warning here
like image 45
Barry Wark Avatar answered Oct 12 '22 10:10

Barry Wark