Re: +poseAsClass and instance variables
Re: +poseAsClass and instance variables
- Subject: Re: +poseAsClass and instance variables
- From: "John C. Randolph" <email@hidden>
- Date: Fri, 22 Feb 2002 15:43:49 -0800
On Friday, February 22, 2002, at 09:41 AM, Darrin Filer wrote:
Is there anyway around the limitation that classes can't have
instance variables when posing as another class? For my
purposes, categories aren't suitable since I need to ensure
that certain methods are overridden.
You can override methods in categories, just not easily use
the original implementation. But on the over side, you cannot
add instance variables in categories either.
One solution is to store your additional variables in a
(static) NSDictionary, using the instance pointer as the key.
Thanks... Although I'm still looking for a technique with very
little overhead.
Explanation:
I'm using posesAsClass to replace normal NSWindows with ones
that are visual quite different. Most of the instance variables
will be used while drawing during live window resizing. Hence,
optimization is sorely needed. Dictionary lookup is nicely
optimized but its still a noticeable hit when compared to
merely accessing an object's value. (right?)
It's hit, sure, but I wouldn't call it a noticeable hit.
In any event, It shouldn't be necessary to use a poser to make
windows with a different appearance, though. You can just use
the technique that Ken Dyke demonstrated in his AlphaWindow
example.
http://nsobject.com/AlphaWindowDemo.src.tgz
I tend to limit my use of posing to cases where I'm debugging
something tricky and I want to (say) log all calls of a
particular method in a class, or if I'm patching around a bug in
a base class.
-jcr
John C. Randolph <email@hidden> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.