• 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: warning: assignment from distinct Objective-C type
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: warning: assignment from distinct Objective-C type


  • Subject: Re: warning: assignment from distinct Objective-C type
  • From: "Julien Jalon" <email@hidden>
  • Date: Tue, 11 Mar 2008 10:16:29 +0100

1) All init methods should return (id) not a specific class2) your
initWithDelegate: is likely too generic as a name and its signature
conflicts with an other one.

Since [XMPPStream alloc] is typed id, the compiler might not be sure of what
method signature you want to use for -initWithDelegate:

In the second case, the compiler knows you are using -[XMPPStream
initWithDelegate:]

I tend to remember that the compiler warning was more specific before
Leopard, maybe a regression.

Nonetheless, good coding style should lead you to rename your method to:

- (id)initXMPPStreamWithDelegate:(id)aDelegate;

instead of:

- (XMPPStream *)initWithDelegate:(id)aDelegate;

--
Julien

On Tue, Mar 11, 2008 at 9:19 AM, Stuart Malin <email@hidden> wrote:

> I have a line of code:
>
>        xmppStream = [[XMPPStream alloc] initWithDelegate:self];
>
> That when compiled, receives a warning:
>
> warning: assignment from distinct Objective-C type
>
> Now, what's odd to me, is if I change the source code to this:
>
>        xmppStream = [XMPPStream alloc];
>        [xmppStream initWithDelegate:self];
>
> It compiles without any warning.
>
> The interface for the XMPPStream initializer is:
>
>        - (XMPPStream*) initWithDelegate:(id)initialDelegate;
>
> And, in the file that is allocating and initializing, the xmppStream
> variable is defined as:
>
>        XMPPStream      *xmppStream;
>
> So I don't see any reason that I should get the warning.
> Any clues about why this happens would be appreciated.
> I'm sure I must be overlooking something obvious...
>
> This is happening with Xcode 2.4.1
>
> [I have posted to both Cocoa and Xcode because I have no idea which
> list would be better for this]
>
>
>
> _______________________________________________
>
> 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
>
_______________________________________________

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

  • Follow-Ups:
    • Re: warning: assignment from distinct Objective-C type
      • From: Stuart Malin <email@hidden>
References: 
 >warning: assignment from distinct Objective-C type (From: Stuart Malin <email@hidden>)

  • Prev by Date: Re: Cocoa way to get list of user accounts?
  • Next by Date: shared NSImage from bundle
  • Previous by thread: Re: warning: assignment from distinct Objective-C type
  • Next by thread: Re: warning: assignment from distinct Objective-C type
  • Index(es):
    • Date
    • Thread