Re: -(id)init methods, NSExceptions, and returning nil
Re: -(id)init methods, NSExceptions, and returning nil
- Subject: Re: -(id)init methods, NSExceptions, and returning nil
- From: Kyle Sluder <email@hidden>
- Date: Mon, 27 Jun 2011 09:30:52 -0700
On Mon, Jun 27, 2011 at 6:38 AM, Roland King <email@hidden> wrote:
>> The favored form for writing an init method seems to be
>>
>> -(id)init
>> {
>> if (self = [super init])
>> {
>> // Do something here
>> }
>> return self;
>> }
>
> actually I think the current favoured method is
>
> -(id)init
> {
> self = [ super init ];
>
> if( self )
> {
> // your code here
> }
>
> return self;
> };
These are equivalent. All you did was move the self assignment out of
the if statement.
I actually prefer to use `if (!(self = [super init])) return nil;`.
Again, it is equivalent.
--Kyle Sluder
_______________________________________________
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