thieumao

Merge Dictionary

May 10th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.33 KB | None | 0 0
  1. extension Dictionary {
  2.    
  3.     mutating func merge(with dictionary: Dictionary) {
  4.         dictionary.forEach { updateValue($1, forKey: $0) }
  5.     }
  6.    
  7.     func merged(with dictionary: Dictionary) -> Dictionary {
  8.         var dict = self
  9.         dictionary.forEach { dict.updateValue($1, forKey: $0) }
  10.         return dict
  11.     }
  12. }
Advertisement
Add Comment
Please, Sign In to add comment