Skip to content

Instantly share code, notes, and snippets.

@jk
Created July 13, 2015 13:26
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 jk/48b90af92812a18d00a2 to your computer and use it in GitHub Desktop.
Save jk/48b90af92812a18d00a2 to your computer and use it in GitHub Desktop.
Merge dictionaries in place as described in http://ericasadun.com/2015/07/08/swift-merging-dictionaries/
extension Dictionary {
mutating func unionInPlace(dictionary: Dictionary<Key, Value>) {
for (key, value) in dictionary {
self[key] = value
}
}
mutating func unionInPlace<S: SequenceType where S.Generator.Element == (Key, Value)>(sequence: S) {
for (key, value) in sequence {
self[key] = value
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment