ios - 双向结构的可用性?
<p><p>我在我的应用程序中遇到了一个需要双向字典数据结构的情况,这意味着一种 NSDictionary,您可以在其中检索带有值的键和带有键的值(所有值和键都是唯一的) .</p>
<p>C/ObjectiveC 中有这样的数据结构吗?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您可以使用 <code>NSDictionary</code>:</p>
<blockquote>
<p>allKeysForObject: Returns a new array containing the keys
corresponding to all occurrences of a given object in the dictionary.</p>
<ul>
<li>(NSArray *)allKeysForObject:(id)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.</li>
</ul>
<p>Discussion Each object in the dictionary is sent an isEqual: message
to determine if it’s equal to anObject.</p>
</blockquote>
<p>还有:</p>
<blockquote>
<p>objectForKey: Returns the value associated with a given key.</p>
<ul>
<li>(id)objectForKey:(id)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.</li>
</ul>
</blockquote></p>
<p style="font-size: 20px;">关于ios - 双向结构的可用性?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/17718241/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/17718241/
</a>
</p>
页:
[1]