Skip navigation.
 
mlRe: warning: assignment from distinct Objective-C type
FROM : Chris Hanson
DATE : Tue Mar 11 21:42:31 2008

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

Related mailsAuthorDate
mlwarning: assignment from distinct Objective-C type Stuart Malin Mar 11, 09:19
mlRe: warning: assignment from distinct Objective-C type Ron Fleckner Mar 11, 09:42
mlRe: warning: assignment from distinct Objective-C type Stuart Malin Mar 11, 09:50
mlRe: warning: assignment from distinct Objective-C type Julien Jalon Mar 11, 10:16
mlRe: warning: assignment from distinct Objective-C type Keary Suska Mar 11, 16:57
mlRe: warning: assignment from distinct Objective-C type Stuart Malin Mar 11, 19:03
mlRe: warning: assignment from distinct Objective-C type Julien Jalon Mar 11, 20:48
mlRe: warning: assignment from distinct Objective-C type Chris Hanson Mar 11, 21:42
mlRe: warning: assignment from distinct Objective-C type Stuart Malin Mar 11, 22:09
mlRe: warning: assignment from distinct Objective-C type Mike Abdullah Mar 11, 22:58
mlRe: warning: assignment from distinct Objective-C type Stuart Malin Mar 11, 23:49
mlRe: warning: assignment from distinct Objective-C type Quincey Morris Mar 11, 23:49
mlRe: warning: assignment from distinct Objective-C type j o a r Mar 11, 23:59
mlRe: warning: assignment from distinct Objective-C type mmalc crawford Mar 12, 01:56
mlRe: warning: assignment from distinct Objective-C type Quincey Morris Mar 12, 02:11
mlRe: warning: assignment from distinct Objective-C type mmalc crawford Mar 12, 06:39
mlRe: warning: assignment from distinct Objective-C type Dennis C. De Mars Mar 12, 17:26
mlRe: warning: assignment from distinct Objective-C type Keith Duncan Mar 12, 23:33