I\'m trying to do the following code that transforms an array of tuples into a dictionary but I\'m receiving a compile error saying:
Immutable value
Swift 4 has a new variant:
var array = [("key0", "value0"), ("key1", "value1")]
var initial = [String: String]()
var final = array.reduce(into: initial) { dictionary, tuple in
dictionary[tuple.0] = tuple.1
}
Which could be expressed:
var array = [("key0", "value0"), ("key1", "value1")]
let final: [String: String] = array.reduce(into: [:]){ $0[$1.0] = $1.1 }