• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: self = [super init], nil?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: self = [super init], nil?
      • From: Kyle Sluder <email@hidden>
References: 
 >self = [super init], nil? (From: "Patrick M. Rutkowski" <email@hidden>)
 >Re: self = [super init], nil? (From: Kyle Sluder <email@hidden>)

  • Prev by Date: Program crashed after edit values at NSTableView
  • Next by Date: Re: Determining when dragging begins and ends
  • Previous by thread: Re: self = [super init], nil?
  • Next by thread: Re: self = [super init], nil?
  • Index(es):
    • Date
    • Thread