Re: Multiple methods named...
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