可可中的双向映射 [英] Bidirectional Map in Cocoa
问题描述
Cocoa提供了NSDictionary,它本质上是一个关联数组。
有一个很好的方法来获得双向关联性?也就是说,如果NSDictionary有一个 keyForObject:
方法,它镜像了 objectForKey:
的行为。 >
我真的不在乎如果NSDictionary不是得到这个的方式。我知道NSDictionary 提供 keysOfEntriesPassingTest:
但它返回一个 NSSet *
这里是一个例子:
fieldMap = [[NSDictionary alloc] initWithObjectsAndKeys:
@c0,@synckey,
@c1,@wi_id,
@ c2,@wi_parent_id,
@c3,@wi_type,
@c4,@wi_rh_task,
@c5
@c6,@wi_stat,
@c7,@wi_prio,
@c8,@wi_cd,
@c9 ,@wi_ct,
@cb,@wi_dh_stat,
@cc,@wi_user,
nil];
我要在 c0 和 synckey davedelong / CHDataStructuresrel =nofollow noreferrer> CHDataStructures 框架具有 CHBidirectionalDictionary 。
Cocoa provides NSDictionary, which essentially is an associative array.
Is there a nice way to get bidirectional associativity? i.e. one way would have been if NSDictionary had a keyForObject:
method which mirrored the behavior of objectForKey:
.
I don't really care if NSDictionary is not the way to get this. I know NSDictionary does provide keysOfEntriesPassingTest:
but it returns an NSSet *
which doesn't look very clean for the kind of thing I want to have.
Here is an example:
fieldMap = [[NSDictionary alloc] initWithObjectsAndKeys:
@"c0",@"synckey",
@"c1",@"wi_id",
@"c2",@"wi_parent_id",
@"c3",@"wi_type",
@"c4",@"wi_rh_task",
@"c5",@"decision_key",
@"c6",@"wi_stat",
@"c7",@"wi_prio",
@"c8",@"wi_cd",
@"c9",@"wi_ct",
@"cb",@"wi_dh_stat",
@"cc",@"wi_user",
nil];
I want to translate between c0 and synckey and back, and ditto for the other fields.
The CHDataStructures framework has CHBidirectionalDictionary.
这篇关于可可中的双向映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!