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:27:34 +0800
On 08-May-2010, at 12:11 PM, Kyle Sluder wrote:
> On May 7, 2010, at 11:34 AM, "Patrick M. Rutkowski" <email@hidden> wrote:
>
>> Will NSObject's init method ever really return nil?
>
> Realistically, no. If it does, there's nothing you can do about it, and you might as well abort. You've probably run out of memory, and I don't believe there's any guarantee that the runtime will be in a consistent state if it can't allocate any objects. I could be wrong about that, but I still wouldn't recommend it.
>
If you're out of memory then it would be alloc returning nil, not init. In that case init wouldn't be called at all. The OP's question was about whether you need to check [ super init ] for nil in your subclass init method, if you get to that point then alloc did manage to allocate an object for you.
Whether you want to also check for the case your entire [ [ MyObject alloc ] init ] returns nil, which it would if allocation failed or if initialization failed is another question, I rarely do unless nil is an anticipated return which means something for that class. _______________________________________________
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