开发者

Xode build warning and "method not found in protocol" when method signature does exist

开发者 https://www.devze.com 2022-12-16 12:26 出处:网络
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.

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


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

#import "ResponseProtocol.h"


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

0

精彩评论

暂无评论...
验证码 换一张
取 消