On Fri, 4 Oct 2013 09:59:53 -0700, Matt Neuburg said:
>-(BOOL)test {
> return [self.celldelegate respond
>sToSelector:@selector(foo:)]; // ...wait for it...
>}
>
>Compile error! No known instance method for selector
>'respondsToSelector:'. WTF???
>
>Here are two ways of fixing the problem. (1) Cast to id:
>
>-(BOOL)test {
> return [(id)self.celldelegate respondsToSelector:@selector(foo:)];
>}
>
>Or, (2) inherit NSObject protocol back in the protocol definition:
>
>@protocol MyCellDelegate<NSObject>
>@end
That's the correct solution.
>But why is either of those necessary? Surely an id<MyCellDelegate> is,
>by definition, an id - which inherits from NSObject,
You've got that backwards. NSObject 'inherits' from id.
respondsToSelector: is part of the NSObject (and NSProxy) protocol. Objects
that aren't subclasses of NSObject might not respond to it.
Cheers,
--
____________________________________________________________
Sean McBride, B. Eng [email protected]
Rogue Research www.rogue-research.com
Mac Software Developer Montréal, Québec, Canada
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]