Created
July 10, 2018 17:57
-
-
Save vkostechko/8350f1f52b832c692912dbaf710166f1 to your computer and use it in GitHub Desktop.
swift dictionary extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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