Check out example codes for "swift map array to dictionary". It will help you in understanding the concepts better.

Code Example 1

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

Learn ReactJs, React Native from akashmittal.com