Convert Dictionary To Array Swift

[Solved] Convert Dictionary To Array Swift | Swift - Code Explorer | yomemimo.com
Question : convert dictionary to array swift

Answered by : fonix

let dic = ["1":"a", "2":"b", "3":"c"]
let arrayOfKeys = Array(dic.keys.map{ $0 })
print(arrayOfKeys) // [1, 2, 3]
let arrayOfValues = Array(dic.values.map{ $0 })
print(arrayOfValues) // [a, b, c]

Source : | Last Update : Wed, 01 Apr 20

Question : swift map array to dictionary

Answered by : upset-unicorn-62eall96mf2f

let myDictionary = myArray.reduce([Int: String]()) { (dict, person) -> [Int: String] in var dict = dict dict[person.position] = person.name return dict
}
//[2: "b", 3: "c", 1: "a"]

Source : https://stackoverflow.com/questions/38454952/map-array-of-objects-to-dictionary-in-swift | Last Update : Thu, 05 Nov 20

Answers related to convert dictionary to array swift

Code Explorer Popular Question For Swift