• 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: Multiple methods named...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Multiple methods named...


  • Subject: Re: Multiple methods named...
  • From: Greg Parker <email@hidden>
  • Date: Sat, 16 Feb 2013 13:51:07 -0800

On Feb 16, 2013, at 2:18 AM, Uli Kusterer <email@hidden> wrote:
> If ClassA and RootA as well are actually identical, you could probably also use instancetype. (good summary here: http://nshipster.com/instancetype/)

instancetype is a good solution when applicable.

Another solution is to lie a little bit to the compiler. In this case, you don't care with method signature the compiler uses at the call site, because both -rootObject declarations are compatible with each other as long as you don't care about strict type checking. It's not like one method returns an object and the other returns a completely incompatible type like float.

You can tell the compiler which one to pick by casting the receiver to a more specific type than id:

    id someRoot = [ (ClassA *)someObject rootObject ];
    // force the compiler to use the declaration for -[ClassA rootObject]


--
Greg Parker     email@hidden     Runtime Wrangler



_______________________________________________

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: 
 >Multiple methods named... (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: Multiple methods named... (From: Uli Kusterer <email@hidden>)

  • Prev by Date: Re: Problem with NSPersistentStore
  • Next by Date: NSDrawer not always sending -drawerDidOpen: to delegate
  • Previous by thread: Re: Multiple methods named...
  • Next by thread: Re: Multiple methods named...
  • Index(es):
    • Date
    • Thread