> On May 25, 2016, at 06:33, Dave <d...@looktowindward.com> wrote:
> 
> 
> Hi,
> 
> I’m getting a warning on the following:
> 
> #import “LTWClassX.h"
> 
> 
> LTWGadgetX*                   myGadgetX;
> Class                         myClass;
> 
> myClass = NSClassFromString(theClassName);
> if (myClass == nil)
>       return nil;
>       
> myGadgetX = [myClass newGadgetInfo];                  //*****Warning - 
> incompatible pointer type assigning to LTWGadgetX from LTWGadgetZ
> 
> 
> newGadgetInfo is define as so:
> 
> +(LTWGadgetX*) newGadgetInfo;
> 
> In LTWGadgetX.h and LTWGadgetX.m
> 
> This code used to use LTWGadgetZ and didn’t produce the warning, now I’ve 
> changed it, it still remembers the LTWGadgetZ definition, which still exists 
> but isn’t included.
> 
> In LTWGadgetZ.h and LTWGadgetZ.m
> 
> +(LTWGadgetZ*) newGadgetInfo;
> 
> I’ve tried cleaning the project but it still moans, how do I fix this?

The compiler doesn’t know which method you’re actually calling, and has no way 
of disambiguating at compile time, so it has to assume that it is one or the 
other; in this case, it’s assuming that it’s LTWGadgetZ. (i.e. it’s not a 
matter of it “remembering” old code, the selection is more or less arbitrary). 
In this case, You have several options:

- Cast (i.e. myGadgetX = (LTWGadgetX *)[myClass newGadgetInfo])
- Change +newGadgetInfo to return id
- Use “id” for myGadgetX’s type
- Use a common superclass of LTWGadgetX and LTWGadgetZ for myGadgetX’s type
- Make a protocol to which  LTWGadgetX and LTWGadgetZ both conform, that 
declares the methods they have in common, and use “id<ThatProtocol>” for 
myGadgetX’s type

-- 
Clark Smith Cox III
clarkc...@gmail.com


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (Xcode-users@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/xcode-users/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to