views:

203

answers:

2

Hello,

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?. Thank you.

-Oscar

+4  A: 

Greg Martin has your answer, but here is a quick explanation of why the compiler complains:

The respondsToSelector: method is part of the NSObject protocol, so when you try to send that message to your deleate (of type id), the compiler has no way of knowing that your delegate might be able to handle it.

e.James
+8  A: 

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

@protocol MyProtocol <NSObject>
Greg Martin
+1 I had no idea that it was possible to inherit protocols. That's going to come in handy!
e.James
I might be doing something wrong but when i add the <NSObject> the compiler complains that no type may be specified before interface
OscarMk
Can you provide your code? Must be a syntax issue.
Greg Martin
I got it working i was trying to implement <NSObject> in the protocol declaration not in the formal definition, it is working now. Thank you.
OscarMk