Swift字典获得价值的钥匙 [英] Swift dictionary get key for value
本文介绍了Swift字典获得价值的钥匙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用[UIImage:UIImage]类型的快速字典,我正在尝试找到给定值的特定键。在Objective-C中,我可以使用allKeysForValue,但对于Swift字典似乎没有这样的方法。我应该使用什么?
I'm using a swift dictionary of type [UIImage:UIImage], and I'm trying to find a specific key for a given value. In Objective-C I could use allKeysForValue, but there appears to be no such method for a Swift dictionary. What should I be using?
推荐答案
如果您使用的是 allKeysForObject
转换为 NSDictionary
:
You can use allKeysForObject
if you cast to NSDictionary
:
let keys = (dict as NSDictionary).allKeysForObject(image) as! [UIImage]
这篇关于Swift字典获得价值的钥匙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文