CodeFlakes
CodeFlakes

Reputation: 3711

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 ?

Upvotes: 12

Views: 3843

Answers (2)

cdespinosa
cdespinosa

Reputation: 20799

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.

Upvotes: 16

Barry Wark
Barry Wark

Reputation: 107754

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

Upvotes: 3

Related Questions