Creates a dictionary by merging the given dictionary into this dictionary, using a combining closure to determine the value for duplicate keys.
SDK
- Xcode 10.2+
Framework
- Swift Standard Library
Declaration
Parameters
other
A dictionary to merge.
combine
A closure that takes the current and new values for any duplicate keys. The closure returns the desired value for the final dictionary.
Return Value
A new dictionary with the combined keys and values of this dictionary and other
.
Discussion
Use the combine
closure to select a value to use in the returned dictionary, or to combine existing and new values. As the key-value pairs in other
are merged with this dictionary, the combine
closure is called with the current and new values for any duplicate keys that are encountered.
This example shows how to choose the current or new values for any duplicate keys: