Re: why isn't id<MyCellDelegate> an id?
Re: why isn't id<MyCellDelegate> an id?
- Subject: Re: why isn't id<MyCellDelegate> an id?
- From: Sean McBride <email@hidden>
- Date: Fri, 04 Oct 2013 13:27:28 -0400
- Organization: Rogue Research Inc.
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@hidden
Rogue Research www.rogue-research.com
Mac Software Developer Montréal, Québec, Canada
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden