views:

142

answers:

2

When I try to invoke an instance of a class that implements a particular protocol, I get warnings about the method not being found in the protocol's signature.

warning: '-requestCompleted:requestType:' not found in protocol(s) warning: 'NSObject' may not respond to '-requestCompleted:requestType:'

I couldn't see the reason for this warning so I copied these classes with no changes into a separate project. When I build the new project, no warnings are generated.

When I execute the code in the original project, everything works fine -- it's just that warnings are shown during the build and I want them to go away.

I've already tried cleaning up my build targets and removing the files in the build directory. What am I not seeing that's causing the warning?

// file one

@protocol ResponseProtocol

- (void)requestCompleted:(NSDictionary *)responseData requestType:(ConnRequestType)lastRequestType;

@end

How I'm calling it:

@interface BaseClass : NSObject 

    __weak NSObject <ResponseProtocol>  *delegate;      
}

- (void)doSomething;

@end

@implementation BaseClass

- (void)doSomething
{
    SEL aSelector = @selector(requestCompleted:requestType:)
    if ((delegate != nil) && [delegate respondsToSelector:aSelector])
    {
        ConnRequestType aRequestType = ...;
        NSDictionary *aResponseData = [NSDictionary dictionary];

        // the following line generates the warnings:
        [delegate requestCompleted:aResponseData requestType:aRequestType];
    }

}

@end
+2  A: 

Make sure you are importing the proper header file in the BaseClass.h file:

#import "ResponseProtocol.h"
Adrian Kosmaczewski
And also, by the way, you can make your delegate ivar of type "id" if you make your ResponseProtocol conform to the NSObject protocol.
Adrian Kosmaczewski
A: 

Have you tried id <ResponseProtocol> delegate instead of NSObject <ResponseProtocol> *delegate? It seems to be the advocated way in Obj-C docs.

Adam Woś