Skip to content

Instantly share code, notes, and snippets.

@RobJDavey
Last active August 29, 2015 14:14
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 RobJDavey/87dcbbb49fbc9556a1ac to your computer and use it in GitHub Desktop.
Save RobJDavey/87dcbbb49fbc9556a1ac to your computer and use it in GitHub Desktop.
Add two swift dictionaries together into a new optional dictionary, result is nil if there were conflicting keys
func +<Key, Value>(lhs: [Key: Value], rhs: [Key: Value]) -> [Key: Value]? {
var result = lhs
for (key, value) in rhs {
if contains(lhs.keys, key) {
return nil
}
result[key] = value
}
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment