Re: self = [super init], nil?
Re: self = [super init], nil?
- Subject: Re: self = [super init], nil?
- From: Roland King <email@hidden>
- Date: Sat, 8 May 2010 12:08:22 +0800
Since NSObject is defined to return self from init the answer to the question is would appear to be no, it cannot return nil.
But .. I cannot think of a good reason not to follow the recommended code, the templated code, all of apple's code (that I've seen thus far) and just check it for nil anyway. This saves you if you change the base class one day, or NSObject's init changes and it seems to me like a really good consistent practice.
On 08-May-2010, at 2:34 AM, Patrick M. Rutkowski wrote:
> Will NSObject's init method ever really return nil?
>
> E.g. if I sub-class NSObject, then is it worth checking for nil after
> doing self = [super init]?
>
> I know there are many classes in UIKit and Cocoa which most definitely
> can return nil from their -init's, as an indication of failure. But
> will this ever be the case with NSObject?
>
> -Patrick
> _______________________________________________
>
> 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
_______________________________________________
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