Sets the value of the specified default key.
SDKs
- iOS 2.0+
- macOS 10.0+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
Framework
- Foundation
Declaration
func set(_ value: Any?, forKey defaultName: String)
Parameters
valueThe object to store in the defaults database.
defaultNameThe key with which to associate the value.
Discussion
The value parameter can be only property list objects: NSData, NSString, NSNumber, NSDate, NSArray, or NSDictionary. For NSArray and NSDictionary objects, their contents must be property list objects. For more information, see What is a Property List? in Property List Programming Guide.
Setting a default has no effect on the value returned by the object(for method if the same key exists in a domain that precedes the application domain in the search list.