FROM : Ben Trumbull
DATE : Mon Feb 11 23:58:34 2008
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
DATE : Mon Feb 11 23:58:34 2008
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
| Related mails | Author | Date |
|---|---|---|
| Scott Andrew | Feb 10, 18:18 | |
| Scott Andrew | Feb 10, 18:35 | |
| Adhamh Findlay | Feb 10, 19:41 | |
| John Newlin | Feb 10, 20:13 | |
| Hans van der Meer | Feb 10, 20:20 | |
| Quincey Morris | Feb 10, 20:29 | |
| Jens Alfke | Feb 10, 20:45 | |
| Wade Tregaskis | Feb 10, 20:50 | |
| Ricky Sharp | Feb 10, 21:01 | |
| Jens Alfke | Feb 10, 22:44 | |
| Hans van der Meer | Feb 10, 23:26 | |
| Paul Bruneau | Feb 10, 23:29 | |
| Uli Kusterer | Feb 10, 23:40 | |
| Paul Bruneau | Feb 11, 00:18 | |
| Scott Andrew | Feb 11, 00:56 | |
| Quincey Morris | Feb 11, 02:32 | |
| mmalc crawford | Feb 11, 02:49 | |
| Jens Alfke | Feb 11, 03:05 | |
| Bill Bumgarner | Feb 11, 03:28 | |
| Quincey Morris | Feb 11, 04:35 | |
| Jean-Daniel Dupas | Feb 11, 10:27 | |
| Jens Alfke | Feb 11, 17:08 | |
| Ben Trumbull | Feb 11, 23:58 |






Cocoa mail archive

