Cocoa touch CocoaTouch:对指针进行散列而不进行复制的词典

Cocoa touch CocoaTouch:对指针进行散列而不进行复制的词典,cocoa-touch,data-structures,Cocoa Touch,Data Structures,我正在寻找一种更好的方法: id key, value; NSMutableDictionary dict; [dict setObject:value forKey:[NSNumber numberWithInt:(int)key]] 也就是说,使用NSDictionary从地址映射到对象。如果可以,请使用C++的映射: std::map<id, id> map; map.insert(std::make_pair(key, value)); std::map; map.inser

我正在寻找一种更好的方法:

id key, value;
NSMutableDictionary dict;
[dict setObject:value forKey:[NSNumber numberWithInt:(int)key]]

也就是说,使用NSDictionary从地址映射到对象。

如果可以,请使用C++的映射:

std::map<id, id> map;
map.insert(std::make_pair(key, value));
std::map;
map.insert(std::make_pair(key,value))
您必须将文件扩展名更改为
.mm
。还请注意,它不会保留您的值。

使用/CFMutableDictionary

CFDictionary的键可以是任何C类型

您需要导入
,并可能将CoreFoundation框架添加到您的项目中


创建字典时,为键和值回调结构指定
NULL
,以表示不希望保留它们。

然后std::unordered\u map,只包含
tr1/unordered\u map
const void * CFDictionaryGetValue (
   CFDictionaryRef theDict,
   const void *key
);