본문 바로가기

Programming/Swift

Class: UserDefaults

Declaration

class UserDefaults : NSObject

Overview

The UserDefaults class provides a programmatic interface for interacting with the defaults system. The defaults system allows an app to customize its behavior to match a user’s preferences. For example, you can allow users to specify their preferred units of measurement or media playback speed. Apps store these preferences by assigning values to a set of parameters in a user’s defaults database. The parameters are referred to as defaultsbecause they’re commonly used to determine an app’s default state at startup or the way it acts by default.

At runtime, you use UserDefaults objects to read the defaults that your app uses from a user’s defaults database. UserDefaultscaches the information to avoid having to open the user’s defaults database each time you need a default value. When you set a default value, it’s changed synchronously within your process, and asynchronously to persistent storage and other processes.

 

Important

Don’t try to access the preferences subsystem directly. Modifying preference property list files may result in loss of changes, delay of reflecting changes, and app crashes. To configure preferences, use the defaults command-line utility in macOS instead.

With the exception of managed devices in educational institutions, a user’s defaults are stored locally on a single device, and persisted for backup and restore. To synchronize preferences and other data across a user’s connected devices, use NSUbiquitousKeyValueStore instead.

 

developer.apple.com/documentation/foundation/userdefaults?changes=_9

 

Apple Developer Documentation

 

developer.apple.com

 

'Programming > Swift' 카테고리의 다른 글

Closures  (0) 2020.11.11
Class: NSManagedObject  (0) 2020.11.11
Class: JSONSerialization  (0) 2020.11.09
Instance Method: dataTask(with:completionHandler:)  (0) 2020.11.08
NSError & CocoaError  (0) 2020.11.06