Updates the value stored in the dictionary for the given key, or adds a new key-value pair if the key does not exist.
- Xcode 10.2+
- Swift Standard Library
The new value to add to the dictionary.
The key to associate with
keyalready exists in the dictionary,
valuereplaces the existing associated value. If
keyisn’t already a key of the dictionary, the
(key, value)pair is added.
The value that was replaced, or
nil if a new key-value pair was added.
Use this method instead of key-based subscripting when you need to know whether the new value supplants the value of an existing key. If the value of an existing key is updated,
update returns the original value.
If the given key is not present in the dictionary, this method adds the key-value pair and returns