• 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: Chris Hanson <email@hidden>
  • Date: Tue, 11 Mar 2008 13:42:31 -0700

On Mar 11, 2008, at 1:19 AM, Stuart Malin wrote:

The interface for the XMPPStream initializer is:

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

The canonical return type of an -init method is (id). So the above should be:


	- (id)initWithDelegate:(id)initialDelegate;

You probably have several different -initWithDelegate: method signatures visible to the compiler at that point in your code, with different return types, and since +alloc also returns (id) it can't necessarily guarantee the right signature will be chosen for the expression. This is part of why Objective-C tends to avoid "generic" names like -initWith: or -initWithDelegate: in favor of slightly more verbose names that are less likely to overlap each other, for example - initWithStreamDelegate: for the above.

Also, once you've upgraded to Leopard and Xcode 3.0, with Objective-C 2.0 you can mark methods in protocols as @required and @optional, which is extremely useful for delegates because (for example) Xcode can perform better code completion than if you define your delegate via an informal protocol (a category on NSObject).

So the above could be:

	- (id)initWithStreamDelegate:(id <XMPPStreamDelegate>)initialDelegate;

Hope this helps!

  -- Chris

_______________________________________________

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: Core Animation Choppyness
  • Next by Date: Re: Working with large files and Memory
  • 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