How to verify if a delegate responds to a selector?

Oscar Gomez picture Oscar Gomez · Feb 10, 2010 · Viewed 11.1k times · Source

I know I need to write:

 [delegate respondsToSelector:@selector(myMethod:)]

But the compiler is complaining that respondsToSelector is not a method in the protocol, which is correct, However I have seen many sample code use this, how do you do it?

Answer

Greg Martin picture Greg Martin · Feb 10, 2010

Your @protocol needs to implement <NSObject>, simply update your protocol definition to look like this:

@protocol MyProtocol <NSObject>