swift dictionary find key from value code example
Example 1: how to get key for dictionary in swift
var array_has_dictionary = [
[
"name" : "xxxx",
"age" : "xxxx",
"last_name":"xxx"
],
[
"name" : "yyy",
"age" : "yyy",
"last_name":"yyy"
],
]
cell.textLabel?.text = Array(array_has_dictionary[1])[1].key
Example 2: swift retrieve value from dictionary
var companies = ["AAPL" : "Apple Inc", "GOOG" : "Google Inc", "AMZN" : "Amazon.com, Inc", "FB" : "Facebook Inc"]
for (key, value) in companies {
print("\(key) -> \(value)")
}
for value in Array(companies.values) {
print("\(value)")
}
print(companies["AAPL"])