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: Quincey Morris <email@hidden>
- Date: Tue, 11 Mar 2008 15:49:34 -0700
On Mar 11, 2008, at 14:09, Stuart Malin wrote:
My rationale for departing from the canonical approach is because
then I get a bit of extra type checking at compile time.
Personally I prefer the factory method approach, a la [NSArray array]
etc:
In your header file:
+ (XMPPStream*) xmppStreamWithDelegate: (id)initialDelegate;
In the implementation:
- (id) initWithDelegate:(id)initialDelegate {...}
+ (XMPPStream*) xmppStreamWithDelegate: (id)initialDelegate {return
[[[XMPPStream alloc] initWithDelegate:initialDelegate] autorelease];}
Usage:
someStream = [XMPPStream xmppStreamWithDelegate:delegate];
This (a) gives you the compile time type check, (b) saves a few
keystrokes of clutter wherever you actually create one of these, (c)
forces creation of the object to use a designated initializer without
chance of mistakes, and (d) allows you to use the proper (id) return
type on your initializers.
_______________________________________________
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