Re: init method ambiguity
Re: init method ambiguity
- Subject: Re: init method ambiguity
- From: Sherm Pendley <email@hidden>
- Date: Thu, 4 Nov 2010 09:03:23 -0400
On Thu, Nov 4, 2010 at 8:23 AM, Jonny Taylor <email@hidden> wrote:
>
> This leads me to believe that what I am writing is not actually doing anything wrong, and the compiler warning is associated with the fact that [MyClassA alloc] returns a plain id leaving the compiler to do some deducing about what the type actually is. This, combined with the confusion of having two methods (for different classes) with the same name but different parameter types, seems to be confusing things.
Exactly.
> One workaround is to include explicit casts like I have shown. However this leaves me wondering whether it goes against convention and/or recommendations to have two init methods with the same name but different parameter types, even for two unrelated different classes (hard to enforce - one could imagine completely different codebases colliding by chance in this respect). Can anybody comment on this?
One question that comes to my mind is whether, given the similarity in
their names, are your two camera classes really *entirely* unrelated?
Is there a common base class, or a protocol they could share? Could
they be made into a class cluster? If so, you could declare your init
like one of these:
-(id)initForCamera:(CameraBase*)cam;
-(id)initForCamera:(id<CameraProtocol>)cam;
sherm--
--
Cocoa programming in Perl:
http://camelbones.sourceforge.net
_______________________________________________
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