Re: Object-C question #1
Re: Object-C question #1
- Subject: Re: Object-C question #1
- From: "M. Uli Kusterer" <email@hidden>
- Date: Wed, 8 Dec 2004 08:11:12 +0100
At 4:16 Uhr +0000 08.12.2004, Thomas Davie wrote:
On 8 Dec 2004, at 04:10, King Chung Huang wrote:
You probably intended to send the parseString: message to yourself.
If so, the initWithString: method should probably look something
like this:
- (id)initWithString:(NSString *)string {
if (self = [super init]) {
[self parseString:string];
}
return self;
}
Actually, your init method should look exactly like this. I've seen
quite a few variants on the init method... But this style is the
only one that captures the correct semantics that cocoa asks for.
What about
-(id) initWithString: (NSString*)string
{
if( !(self = [super init]) )
return nil;
[self parseString: string];
return self;
}
Catches the same semantics, and IMHO makes the code more readable if
you have a lot of initialization statements.
Also, you will probably want to put an extra pair of brackets around
your assignment statement in the "if". That shuts up GCC's warning
about "possibly unwanted assignment".
--
Cheers,
M. Uli Kusterer
------------------------------------------------------------
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden