Re: Sensible way to extend base class?
Re: Sensible way to extend base class?
- Subject: Re: Sensible way to extend base class?
- From: Greg Parker <email@hidden>
- Date: Wed, 20 May 2009 13:29:21 -0700
On May 20, 2009, at 8:21 AM, Keith Duncan wrote:
One would think that given the Objective-C 2.0 runtime (which is
only available on iPhone OS, or 64-bit mode in Mac OS, ARGH!) and
its support for iVar layouts, adding an ivar to an existing class
would be possible. Since it isn't [...]
I thought that was one of the features of the Objective-C 2.0
runtime, is a non-fragile base class. Enabled by runtime computed
instance variable offsets
Rearranging ivars works great until someone calls +alloc. Then your
class is locked, because you can't change those instances later. In
theory the runtime could allow you to change ivars at runtime as long
as nobody has allocated anything yet (or looked up ivar offsets, or a
few other things), but that's an awful lot of bookkeeping for not much
gain.
which is why direct instance variable access is highly discouraged
in any Objective-C 2.0 code.
Direct ivar access is not discouraged (at least, not any more than it
always has been for other reasons). `self->ivar` or just `ivar` both
use the runtime-computed offsets.
--
Greg Parker email@hidden Runtime Wrangler
_______________________________________________
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