Answers for "swift get keys from dictionary"

3

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)")
}

//Or if you only want the values:

for value in Array(companies.values) {
    print("\(value)")
}
// One value with direct access on the dictionary:

print(companies["AAPL"])
Posted by: Guest on March-05-2020
0

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)
} // 2
Posted by: Guest on October-15-2020
0

swift get keys from dictionary

componentArray = Array(dict.keys) // for Dictionary

componentArray = dict.allKeys // for NSDictionary
Posted by: Guest on October-27-2021

Code answers related to "swift get keys from dictionary"

Code answers related to "Swift"

Browse Popular Code Answers by Language