Skip to content

Instantly share code, notes, and snippets.

@RinniSwift
Created June 1, 2019 23:37
Show Gist options
  • Save RinniSwift/ff301603b27294778efb7d720fffaec7 to your computer and use it in GitHub Desktop.
Save RinniSwift/ff301603b27294778efb7d720fffaec7 to your computer and use it in GitHub Desktop.
var dict = ["blue": 2, "grey": 1, "red": 2]
var newDict = ["pink": 3, "red": 5]
dict.merge(newDict) { (current, _) in current } // ["blue": 2, "grey": 1, "red": 2, "pink": 3]
dict.merge(newDict) { (_, new) in new } // ["blue": 2, "grey": 1, "red": 5, "pink": 3]
let mergedDict = dict.merging(newDict) { (current, _) in current} // ["blue": 2, "grey": 1, "red": 5, "pink": 3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment