Re: warning: assignment from distinct Objective-C type
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
|
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden