I added Dictionary extension
extension Dictionary {
func cloneWith(_ dict: [Key: Value]) -> [Key: Value] {
var result = self
dict.forEach { key, value in result[key] = value }
return result
}
}
you can use cloneWith
like this
newDictionary = dict.reduce([3 : "efg"]) { r, e in r.cloneWith(e) }