views:

1705

answers:

1

Hey there,

Does anyone know the best way to check to see if an optional protocol method has been implemented.

I tried this:

if ([self.delegate respondsToSelector:@selector(optionalProtocolMethod:)] )

where delegate is:

id<MyProtocol> delegate;

However - I get an error saying that the function respondsToSelector is not found in the protocol!

Thanks for any help! Cheers, Nick.

+34  A: 

respondsToSelector: is part of the NSObject protocol. Including NSObject in MyProtocol should solve your problem:

@protocol MyProtocol <NSObject>

@optional
-(void)optionalProtocolMethod:(id)anObject;

@end
Will Harris
Genius... just tried this and it worked a dream. Thanks!
Nick Cartwright
thx a lot, this saved me some time.
microspino