Instance Method

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 Accessing Object Properties).

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

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