Instance Method


Adds a given key-value pair to the dictionary.


func setValue(_ value: Any?, forKey key: String)



The value for key.


The key for value. Note that when using key-value coding, the key must be a string (see Accessing Object Properties).


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:).

See Also

Adding Entries to a Mutable Dictionary

func setObject(Any, forKey: NSCopying)

Adds a given key-value pair to the dictionary.

func addEntries(from: [AnyHashable : Any])

Adds to the receiving dictionary the entries from another dictionary.

func setDictionary([AnyHashable : Any])

Sets the contents of the receiving dictionary to entries in a given dictionary.