swift dictionary 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: create dictionary swift
var someDict:[String:Int] = ["One":1, "Two":2, "Three":3]
var someVar = someDict["One"]
print("The value of key = One is \(someVar)")
Example 3: dictionary in swift
var someDict = [KeyType: ValueType]()
Example 4: how to get list of value from specific keys in array object in swift
import Foundation
let strings = [
"one",
"two",
"three"
]
let ints = strings.map { (string) -> Int in
return string.count
}