Swift:使用值查询字典

时间:2017-03-01 19:22:07

标签: swift dictionary nsdictionary xcode8

我有一本字典,但我需要按特定值查询才能获得密钥。但似乎swift没有valueforKey功能。

示例:

print(myDictionary["key"])
//output: 100

//but I want to get:
print(myDictionary.valueForkey:"100")
//output: key

你们中的任何一个人都知道如何在swift中做到这一点?

1 个答案:

答案 0 :(得分:3)

当然你可以在Swift中做到这一点,因为字典可以用元组表示:

ef0S2QX5mmey5LOWAAAB