• 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: The Power of Init
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: The Power of Init


  • Subject: Re: The Power of Init
  • From: j o a r <email@hidden>
  • Date: Tue, 20 Dec 2005 21:52:21 +0100


On 20 dec 2005, at 21.38, Jonathan Faulkenberry wrote:

Yet another newbie question, why does Apple recommend (through the code completion function) that may init function should include a if (self != nil) statement? How could self be equal to nil anyway?

It usually looks something like this:

if (nil != (self = [super init]))
// do stuff

The point here being that one of your superclasses could decide that it's not a good time to create a new instance (bad parameters would be the most likely cause) and as a result return nil from init. As a subclass you should look out for that, and only perform initialization code if the superclass initialized successfully.

j o a r


Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
References: 
 >The Power of Init (From: Jonathan Faulkenberry <email@hidden>)

  • Prev by Date: The Power of Init
  • Next by Date: NSSQLiteStoreType: getting "...NSFaultingMutableSet bytes]: selector not recognized..." runtime errors
  • Previous by thread: The Power of Init
  • Next by thread: NSSQLiteStoreType: getting "...NSFaultingMutableSet bytes]: selector not recognized..." runtime errors
  • Index(es):
    • Date
    • Thread