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.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software