• 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] debate.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: self = [super init] debate.


  • Subject: Re: self = [super init] debate.
  • From: Jean-Daniel Dupas <email@hidden>
  • Date: Mon, 11 Feb 2008 10:27:48 +0100


id newSelf = [super init];

if (self == newSelf) {
	...
} else {
	[self release];
	self = newSelf;
}

return self;


However, that's assuming super always returns either self or an existing, fully-initialised instance, which as noted previously doesn't have to be the case...

Generally, protecting against nil should be quite sufficient, as noted, and in the few cases where a class does do funky voodoo in its initialisers, it should document as such and explain exactly what it could hypothetically do, so you can write your subclasses appropriately.

I disagree with this example. I think, it's the super class responsability to release self.
The [super init] should be like this:


{
	[self release];
	return singletonInstance;
}


_______________________________________________

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] debate.
      • From: Jens Alfke <email@hidden>
References: 
 >self = [super init] debate. (From: Scott Andrew <email@hidden>)
 >Re: self = [super init] debate. (From: Scott Andrew <email@hidden>)
 >Re: self = [super init] debate. (From: Adhamh Findlay <email@hidden>)
 >Re: self = [super init] debate. (From: John Newlin <email@hidden>)
 >Re: self = [super init] debate. (From: Wade Tregaskis <email@hidden>)

  • Prev by Date: Re: Logging Mechanisms in Cocoa
  • Next by Date: Re: nspopupbuttoncell attribs
  • Previous by thread: Re: self = [super init] debate.
  • Next by thread: Re: self = [super init] debate.
  • Index(es):
    • Date
    • Thread