add optional dictionary convenience function

This commit is contained in:
Kyle Matthew Hedden 2020-09-21 12:19:28 -04:00
parent e0833fbdcf
commit f2102492f6

View File

@ -193,3 +193,13 @@ public extension Dictionary {
return previousObject
}
}
public extension Optional where Wrapped == Dictionary<AnyHashable, Any> {
func dictionaryAdding(key: AnyHashable, value: Any) -> Dictionary<AnyHashable, Any> {
var dictionary = self ?? [:]
dictionary[key] = value
return dictionary
}
}