• 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: +poseAsClass and instance variables
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: +poseAsClass and instance variables
      • From: Darrin Filer <email@hidden>
References: 
 >Re: +poseAsClass and instance variables (From: Darrin Filer <email@hidden>)

  • Prev by Date: Re: RE What to do? (I have a simple method for doing it)
  • Next by Date: Re: number formatting
  • Previous by thread: Re: +poseAsClass and instance variables
  • Next by thread: Re: +poseAsClass and instance variables
  • Index(es):
    • Date
    • Thread