Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vkostechko/8350f1f52b832c692912dbaf710166f1 to your computer and use it in GitHub Desktop.
Save vkostechko/8350f1f52b832c692912dbaf710166f1 to your computer and use it in GitHub Desktop.
swift dictionary extension
extension Dictionary {
static func union(dic: Dictionary, other: Dictionary?) -> Dictionary {
var mutableCopy = dic
mutableCopy.add(other: other)
return mutableCopy
}
mutating func add(other: Dictionary?) -> Void {
guard let other = other else { return }
other.forEach { (key, value) in
self.updateValue(value, forKey:key)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment