Re: init returns nil or raises exception?
Re: init returns nil or raises exception?
- Subject: Re: init returns nil or raises exception?
- From: Remco Poelstra <email@hidden>
- Date: Fri, 8 Oct 2010 10:14:18 +0200
Op 8 okt 2010, om 09:57 heeft Kyle Sluder het volgende geschreven:
> On Fri, Oct 8, 2010 at 12:04 AM, Remco Poelstra <email@hidden> wrote:
>> Ah, I see. I hoped it was 'the new way to go'. I like to more than checking
>> for nil, but I might be a bit lazy :)
>
> Checking for nil and assigning to self should be reflexes. You can
> combine the two if you like. Whenever I write an -init method, I
> always follow the same pattern. I don't even need to think about it:
>
> - (id)init {
> if (!(self = [super init]))
> return nil;
>
> // do other initialization
>
> return self;
> }
>
> To my brain, it might as well be required syntax.
Yes, but in the rest of my code I've to do the check as well, so this is actually not a good thing to do:
[someObject doSomethingWithObject:[CustomClass customClassObjectThatMightBeNil]];
Assuming there is also a convenience class method that calls that same init as above.
Regards,
Remco Poelstra_______________________________________________
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