Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SWIFT

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"]
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #swift #map #array #dictionary
ADD COMMENT
Topic
Name
5+7 =