• 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: Sensible way to extend base class?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Sensible way to extend base class? (From: Graham Cox <email@hidden>)
 >Re: Sensible way to extend base class? (From: Jerry Krinock <email@hidden>)
 >Re: Sensible way to extend base class? (From: Graham Cox <email@hidden>)
 >Re: Sensible way to extend base class? (From: Jonathan del Strother <email@hidden>)
 >Re: Sensible way to extend base class? (From: Gwynne Raskind <email@hidden>)
 >Re: Sensible way to extend base class? (From: Keith Duncan <email@hidden>)

  • Prev by Date: Re: Network Reachability APIs
  • Next by Date: Re: Network Reachability APIs
  • Previous by thread: Re: Sensible way to extend base class?
  • Next by thread: Re: Sensible way to extend base class?
  • Index(es):
    • Date
    • Thread