Re: NSMapTable on iOS?
Re: NSMapTable on iOS?
- Subject: Re: NSMapTable on iOS?
- From: James Montgomerie <email@hidden>
- Date: Fri, 08 Jul 2011 11:05:03 -0700
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 (email@hidden)
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:
This email sent to email@hidden