pulkitsinghal
pulkitsinghal

Reputation: 4084

How to get around incorrect warning in Xcode?

I'm receiving the following warning:

Instance method 'method name' not found (return type defaults to 'id')

when this code is invoked:

@protocol SomeProtocol <NSObject> {
    @property (nonatomic, retain) SpecificClassName* someDelegate;
}
...
+ (void) aMethod : (id <SomeProtocol>) object {
    [object.someDelegate doSomeThing]; // warning statement show up here
}

I feel like this is a short coming of the compiler at this point, but that just may be the pot calling the kettle black ... does anyone have any feedback on this?

Upvotes: 0

Views: 103

Answers (2)

joerick
joerick

Reputation: 16458

You need to #import the header file for SpecificClassName, in your implementation (.m file).

If you're going to use the type name SpecificClassName in the header file, a forward declaration @class SpecificClassName will do, but calling a method on the class requires the compiler to know the return type of the method.

If you want to call a method on an instance of SpecificClassName, include the header in which it's defined.

Upvotes: 1

Mike Baranczak
Mike Baranczak

Reputation: 8374

I means that the header file for the class doesn't include the method signature. So the compiler can't tell if the method is actually there. Fix the header file to get rid of the warning.

In Java or C++, this would be a compilation failure. That's because they do method binding at compile-time, so the compiler needs to find the methods. Objective-C does it at run-time; it sends a method call to an object, and the object may or may not have such a method.

Upvotes: 0

Related Questions