setValue(_:forKey:)
Adds a given key-value pair to the dictionary.
Declaration
func setValue(_ value: Any?, forKey key: String)Parameters
- value:
The value for
key. - key:
The key for
value. Note that when using key-value coding, the key must be a string (see 20002170).
Discussion
This method adds value and key to the dictionary using setObject(_:forKey:), unless value is nil in which case the method instead attempts to remove key using removeObject(forKey:).