• 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: Ben Trumbull <email@hidden>
  • Date: Mon, 11 Feb 2008 14:58:34 -0800

Mostly, Bill, Jens and others have covered the topic. I'd like to hilight a couple of points.

(1) NSManagedObject *requires* you assign to self. This is documented, not debatable, not stylistic. On 10.5, you're pretty much never going to get back the result of +alloc. Malcolm sent a link to the explanation (*)

(2) You are quite welcome to subclass from class clusters, although it does require some care.

(*) One of the key assumptions in Wil's original reasoning is that a call to super's init could not possibly return anything besides your subclass because none of your subclass's ivars would be accessible. This is assumption is flawed.

The super class can ask the Objective-C runtime to tell it everything it needs to know about your subclass and its ivars to make things right. Both Core Data and Key Value Observing work with a dynamically created subclass of your subclass.

This assumption is especially flawed under 64 bit with non-fragile ivars as the requisite sophistication is much reduced.

There are other reasons why a super class might return a different instance, even if it did give you back your subclass. For example, it could use the extraBytes parameter of NSAllocateObject() or otherwise "move" your instance in memory. Perhaps to a different zone, or some other nefarious purpose.
--


-Ben
_______________________________________________

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


  • Prev by Date: Re: @property problem
  • Next by Date: Re: NSCollectionView questions
  • Previous by thread: Re: self = [super init] debate.
  • Next by thread: Xcode 3.0, is it missing the Close Project menu item?
  • Index(es):
    • Date
    • Thread