我在我的应用程序中遇到了一个需要双向字典数据结构的情况,这意味着一种 NSDictionary,您可以在其中检索带有值的键和带有键的值(所有值和键都是唯一的) .
C/ObjectiveC 中有这样的数据结构吗?
您可以使用 NSDictionary
:
allKeysForObject: Returns a new array containing the keys corresponding to all occurrences of a given object in the dictionary.
- (NSArray *)allKeysForObjectid)anObject Parameters anObject The value to look for in the dictionary. Return Value A new array containing the keys corresponding to all occurrences of anObject in the dictionary. If no object matching anObject is found, returns an empty array.
Discussion Each object in the dictionary is sent an isEqual: message to determine if it’s equal to anObject.
还有:
objectForKey: Returns the value associated with a given key.
- (id)objectForKeyid)aKey Parameters aKey The key for which to return the corresponding value. Return Value The value associated with aKey, or nil if no value is associated with aKey.
关于ios - 双向结构的可用性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17718241/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |