On 8 Jul 2011, at 00:30, Dave Keck wrote: >> Kind of surprised to discover that NSMapTable doesn’t exist on iOS (even the >> older procedural form of the API). I need a non-retaining dictionary — do I >> need to drop down to CFDictionary or is there some higher-level alternative? > > I was surprised by this too, but found the CFDictionary alternative palatable: > > // weak opaque-pointer keys > // strong object values > NSMutableDictionary *b = (id)CFDictionaryCreateMutable(nil, 0, > nil, &kCFTypeDictionaryValueCallBacks); > > // strong object keys > // weak opaque-pointer values > NSMutableDictionary *a = (id)CFDictionaryCreateMutable(nil, 0, > &kCFTypeDictionaryKeyCallBacks, nil); > > // weak opaque-pointer keys > // weak opaque-pointer values > NSMutableDictionary *c = (id)CFDictionaryCreateMutable(nil, 0, nil, nil);
Watch out - if you use toll-free-bridged NSMutableDictionary methods to set objects in a mutable CFDictionary with custom key callbacks, the key will be copied even if you've specified a custom key callback when creating the dictionary. To not copy the keys (i.e. work as I, at least, would expect), you must use the CFDictionary functions to add items. More information: http://www.cocoabuilder.com/archive/cocoa/163407-using-nsimages-as-keys-to-dictionary.html#163439 Jamie. _______________________________________________ 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