• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: why isn't id<MyCellDelegate> an id?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >why isn't id<MyCellDelegate> an id? (From: Matt Neuburg <email@hidden>)

  • Prev by Date: Re: why isn't id<MyCellDelegate> an id?
  • Next by Date: Re: Doc Viewer in 5.0.1
  • Previous by thread: Re: why isn't id<MyCellDelegate> an id?
  • Next by thread: Re: why isn't id<MyCellDelegate> an id?
  • Index(es):
    • Date
    • Thread