On 11/06/2009, at 18:41 , Jo Meder wrote:
It would be great to be able to do this for NSViews but I haven't been able to find any equivalent. Are there any ingenious ways that you might be aware of so I could bolt this on to NSView?

I have yet to find a good solution to this.

It would be fantastic if NSView had an NSDictionary field and Interface Builder let you set values in the dictionary. Given the pain of writing Interface Builder plugins, this would be a much easier solution to a bunch of problems where you want a custom view to have some configuration.

The only vaguely approximate thing is the tag field in NSControl, which you can subvert for some purposes, but it is very limited.

I'm trying to avoid setting up a map from NSViews to UI framework objects, but I suspect it will be inevitable. Not really a big deal, but less hassle to be able to associate the data directly so that would be a preferable solution.

The only alternative I could see would be to create a global NSDictionary mapping NSView* to UI framework objects, use message swizzling on NSView to swap out its init and dealloc methods, and add a category on NSView to access the UI framework objects via the global dictionary. Slightly ugly to write and then trivial to use. You probably don't need to swizzle the init methods, just create the global dictionary entry on demand as necessary, but you do need to swizzle the dealloc method to know when to get rid of the entry.

Enjoy,
   Peter.

--
     Clipboard Switching and Macros with Keyboard Maestro

Keyboard Maestro <http://www.keyboardmaestro.com/> Macros for your Mac
<http://www.stairways.com/>           <http://download.stairways.com/>



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to