“Swift Map Array to Dictionary” Code-Antworten

Wörterbuch in Array Swift konvertieren

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]
Fonix

Swift Map Array to Dictionary

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"]
Upset Unicorn

Ähnliche Antworten wie “Swift Map Array to Dictionary”

Fragen ähnlich wie “Swift Map Array to Dictionary”

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen