swift get specific value from dictionary using key code example
Example 1: 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"])
Example 2: swift dictionary get key from valye
let dict: [Int: String] = [1: "one", 2: "two", 4: "four"]
if let key = dict.someKey(forValue: "two") {
print(key)
}