• 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: Using NSImages as keys to a dictionary
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using NSImages as keys to a dictionary


  • Subject: Re: Using NSImages as keys to a dictionary
  • From: Sherm Pendley <email@hidden>
  • Date: Sat, 13 May 2006 17:32:23 -0400

On May 13, 2006, at 5:16 PM, Michael Ash wrote:

On 5/13/06, Adam R. Maxwell <email@hidden> wrote:

Another way to do this might be to create a CFMutableDictionary with custom callbacks that retain keys instead of copying them, and compares keys based on pointer equality; with toll-free bridging, you'd just treat it as a standard NSMutableDictionary. You have to ensure that the hash of the keys (NSImage instances) doesn't change while they're in the dictionary, though.

Sadly, this doesn't work. While you can indeed treat such a CFMutableDictionary as an NSMutableDictionary, the Cocoa methods will not respect your custom callbacks. In other words, if you create a CFMutableDictionary which does not copy its keys, then do [myCFDict setObject:obj forKey:key], key *will* be copied.

I consider this a bug and have filed it as rdar://4350677 . The
obvious workaround is to use the actual CF functions instead, which is
not really a problem.

You could implement a subclass of the NSDictionary and NSMutableDictionary class clusters, using primitive methods that typecast "self" and call the CF functions. The result is an object that conforms to the standard NSMutableDictionary interface, but does respect your custom callbacks.


sherm--

Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org

_______________________________________________
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


References: 
 >Using NSImages as keys to a dictionary (From: "Lawrence Sanbourne" <email@hidden>)
 >Re: Using NSImages as keys to a dictionary (From: Greg Hurrell <email@hidden>)
 >Re: Using NSImages as keys to a dictionary (From: "Adam R. Maxwell" <email@hidden>)
 >Re: Using NSImages as keys to a dictionary (From: "Michael Ash" <email@hidden>)

  • Prev by Date: Re: Rotating Image Button
  • Next by Date: Should I retain/release IBOutlet?
  • Previous by thread: Re: Using NSImages as keys to a dictionary
  • Next by thread: Re: Using NSImages as keys to a dictionary
  • Index(es):
    • Date
    • Thread