Ios Objective-C比较和替换NSMutableDictionary值的快速方法

Ios Objective-C比较和替换NSMutableDictionary值的快速方法,ios,objective-c,nsmutabledictionary,Ios,Objective C,Nsmutabledictionary,我有两个不同长度的NSMutableDictionary,如下所示: Dic 1: { 0 = 22962; 10 = 11762; 11 = 11762; 12 = 11761; 13 = 11761; 2 = 11762; 3 = 11761; 4 = 11763; 5 = 11763; 6 = 11763; 7 = 11763; 8 = 11763; 9 = 11762;} Dic 2: { 11756 = "<EPinObject: 0x17009f860>"; 11761

我有两个不同长度的NSMutableDictionary,如下所示:

Dic 1: {
0 = 22962;
10 = 11762;
11 = 11762;
12 = 11761;
13 = 11761;
2 = 11762;
3 = 11761;
4 = 11763;
5 = 11763;
6 = 11763;
7 = 11763;
8 = 11763;
9 = 11762;}

Dic 2: {
11756 = "<EPinObject: 0x17009f860>";
11761 = "<EPinObject: 0x17409f950>";
11757 = "<EPinObject: 0x1700973e0>";
11762 = "<EPinObject: 0x17409f9f0>";
11758 = "<EPinObject: 0x174280410>";
11763 = "<EPinObject: 0x17409fa40>";
11759 = "<EPinObject: 0x174280460>";
11760 = "<EPinObject: 0x1742804b0>";
22962 = "<EPinObject: 0x17409f9a0>";}
Dic 3: {
0 = "<EPinObject: 0x17409f9a0>";
10 = "<EPinObject: 0x17409f9f0>";
...
9 = "<EPinObject: 0x17409f9f0>";}
Dic 1:{
0 = 22962;
10 = 11762;
11 = 11762;
12 = 11761;
13 = 11761;
2 = 11762;
3 = 11761;
4 = 11763;
5 = 11763;
6 = 11763;
7 = 11763;
8 = 11763;
9 = 11762;}
Dic 2:{
11756 = "";
11761 = "";
11757 = "";
11762 = "";
11758 = "";
11763 = "";
11759 = "";
11760 = "";
22962 = "";}
我想让Dic 3像这样:

Dic 1: {
0 = 22962;
10 = 11762;
11 = 11762;
12 = 11761;
13 = 11761;
2 = 11762;
3 = 11761;
4 = 11763;
5 = 11763;
6 = 11763;
7 = 11763;
8 = 11763;
9 = 11762;}

Dic 2: {
11756 = "<EPinObject: 0x17009f860>";
11761 = "<EPinObject: 0x17409f950>";
11757 = "<EPinObject: 0x1700973e0>";
11762 = "<EPinObject: 0x17409f9f0>";
11758 = "<EPinObject: 0x174280410>";
11763 = "<EPinObject: 0x17409fa40>";
11759 = "<EPinObject: 0x174280460>";
11760 = "<EPinObject: 0x1742804b0>";
22962 = "<EPinObject: 0x17409f9a0>";}
Dic 3: {
0 = "<EPinObject: 0x17409f9a0>";
10 = "<EPinObject: 0x17409f9f0>";
...
9 = "<EPinObject: 0x17409f9f0>";}
Dic 3:{
0 = "";
10 = "";
...
9 = "";}
Dic 1对于diff key有相似的值,所以我必须这样放置

现在我用2来表示in,但它似乎太长,循环太多,我想知道是否有更快的方法来比较dic1的值和dic2的键,并生成dic3?

一个用于:

dict3 = [dict1 mutableCopy]
for (id<NSCopying> key in dict3.allKeys) {
    dict3[key] = dict2[dict3[key]];
}
更新:通过@Caleb的改进(以及一些优化):

一个用于:

dict3 = [dict1 mutableCopy]
for (id<NSCopying> key in dict3.allKeys) {
    dict3[key] = dict2[dict3[key]];
}
更新:通过@Caleb的改进(以及一些优化):


@Tj3n,不客气:)我更新了答案以使用您的符号(
dict1
/
dict2
/
dict3
),非常感谢!我还在想办法使用键和值快速枚举可以使用字典,所以你可以删除
.allKeys
,我认为你也不需要
对于(dict3中的id键){…
@Caleb,谢谢你建议的改进。但是,如果我们只删除
allKeys
,它会崩溃(集合在枚举时发生了变异)。但是,由于
dict3
dict1
的副本,我们可以在
中用
dict1
替换
dict3
。我稍后会添加最终版本。@Tj3n,不客气:)我更新了答案以使用您的符号(
dict1
/
dict2
/
dict3
)。非常感谢!我仍在想办法使用键和值快速枚举可以使用字典,因此您可以删除
。所有键
,而且我认为您也不需要
(dict3中的id键)的
{…
@Caleb,感谢您提出的改进建议。但是,如果我们只删除
所有密钥
,它将崩溃(集合在枚举时发生了变异)。但是,由于
dict3
dict1
的副本,我们可以在
中用
dict1
替换
dict3
。我稍后将添加最终版本。