On May 11, 2010, at 1:36 PM, Alejandro Marcos Aragón wrote:

I'm new to Cocoa, and I couldn't find information about an error that I'm getting on the web. I'm trying to create an NSMutableDictionary where the keys are of type UIButton*:

Sounds like you're trying to associate data values with buttons. The easiest way to do this is to use the control's existing 'tag' property, which lets you store an arbitrary integer value. [Actually I'm not certain that UIKit controls have tags; their corresponding AppKit classes in Mac OS do.]

If you need to store a non-integer value, or have to use a dictionary for some other reason, you can use [NSValue valueWithPointer: button] to create a value object wrapping a pointer to your button. Those values can be used as dictionary keys. To unwrap one, use (UIButton*) [value pointerValue]. Just make sure to remove the associated key object when a button is deleted, otherwise it's a dangling pointer to a deleted object and will cause a crash if you try to use that button pointer again.

—Jens_______________________________________________

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