Re: Inserting a custom class into class hierarchy?
Re: Inserting a custom class into class hierarchy?
- Subject: Re: Inserting a custom class into class hierarchy?
- From: Glenn Andreas <email@hidden>
- Date: Sat, 4 Dec 2004 09:11:24 -0600
At 7:53 AM -0500 12/4/04, The Karl Adam wrote:
On Sat, 4 Dec 2004 08:58:37 +0100, M. Uli Kusterer
<email@hidden> wrote:
At 18:38 Uhr -0500 03.12.2004, The Karl Adam wrote:
> >Add a poseAsClass to your MyObject to have it pose as NSObject,
>however be forewarned that you then need to make sure your app doesn't
>explode, the world doesn't end and you didn't tear a hole in the space
>time continuum. All that said:
Didn't poseAsClass: have the requirement that you don't add any
instance variables to your subclass?
hmm, according to the docs you are correct, the subclass cannot add
any instance variables, so you'd have to use the poseAsClass in
addition to the CustomIvarStruct or an NSHashMap, but however you
handle your added instance data, it iwould have to be external to the
MyObject class.
And at that point (i.e., you've got an external method to associate
additional ivars with an object which can be accessed via normal
accessor methods), you might as well just use a category to add the
functionality and skip messing with poseAsClass.
poseAsClass should be one of the last resorts (though probably a step
above manually changing superclass pointers, or the isa pointers of
the metaclass). One problem is that anything already created as the
old class will remain as the old class (while "external ivars" +
category will work for existing objects). (And yes, bindings use
poseAsClass to accomplish adding KVO).
Perhaps if there is enough interest, I can pull together a bunch of
"runtime class modification" examples I've got (if you grab the
source for PyOXIDE you'll find a category that add a python
interpreter to all NSDocuments, while IDEKit has dynamic class
generation code).
--
Glenn Andreas email@hidden
<http://www.gandreas.com/> oh my!
Mad, Bad, and Dangerous to Know
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden