Mac Developer Library

Developer

AppKit Framework Reference NSUserDefaultsController Class Reference

Options
Deployment Target:

On This Page
Language:

NSUserDefaultsController

NSUserDefaultsController is a Cocoa bindings compatible controller class. Properties of the shared instance of this class can be bound to user interface elements to access and modify values stored in NSUserDefaults.

Inheritance


Conforms To


Import Statement


import AppKit @import AppKit;

Availability


Available in OS X v10.3 and later.
  • Returns the shared instance of NSUserDefaultsController, creating it if necessary.

    Declaration

    Swift

    class func sharedUserDefaultsController() -> NSUserDefaultsController

    Objective-C

    + (NSUserDefaultsController *)sharedUserDefaultsController

    Discussion

    This instance has no initial values, and uses [NSUserDefaults standardUserDefaults] to create the defaults. An application can get this object when an application launches and configure it as required.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Returns an initialized NSUserDefaultsController object using the NSUserDefaults instance specified in defaults and the initial default values contained in the initialValues dictionary.

    Declaration

    Swift

    init(defaults defaults: NSUserDefaults?, initialValues initialValues: [NSObject : AnyObject]?)

    Objective-C

    - (instancetype)initWithDefaults:(NSUserDefaults *)defaults initialValues:(NSDictionary *)initialValues

    Discussion

    If defaults is nil, the receiver uses [NSUserDefaults standardUserDefaults].

    This method is the designated initializer.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Returns the instance of NSUserDefaults in use by the receiver.

    Declaration

    Swift

    var defaults: NSUserDefaults { get }

    Objective-C

    @property(readonly, strong) NSUserDefaults *defaults

    Discussion

    This property is observable using key-value observing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Sets the receiver’s initial values to initialValues.

    Declaration

    Swift

    var initialValues: [NSObject : AnyObject]?

    Objective-C

    @property(copy) NSDictionary *initialValues

    Discussion

    These values are used when a user default properties has no value in NSUserDefaults and by revertToInitialValues:.

    The initial values must be set before loading a nib that uses the receiver, as those values may be referenced at load time. It is good practice to set the initial values–along with registering any defaults for the applications–in theinitialize class method of your preference dialog controller, or the application delegate.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Returns whether the receiver has user default values that have not been saved to NSUserDefaults.

    Declaration

    Swift

    var hasUnappliedChanges: Bool { get }

    Objective-C

    @property(readonly) BOOL hasUnappliedChanges

    Discussion

    This property is observable using key-value observing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Returns a dictionary containing the receiver’s initial default values.

    Declaration

    Swift

    var initialValues: [NSObject : AnyObject]?

    Objective-C

    @property(copy) NSDictionary *initialValues

    Discussion

    These values are used when is no value found for the bound property in defaults.

    This property is observable using key-value observing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Sets whether any changes made to the receiver’s user default properties are saved immediately.

    Declaration

    Swift

    var appliesImmediately: Bool

    Objective-C

    @property BOOL appliesImmediately

    Discussion

    The default is YEStrue.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Returns whether any changes made to bound user default properties are saved immediately.

    Declaration

    Swift

    var appliesImmediately: Bool

    Objective-C

    @property BOOL appliesImmediately

    Discussion

    Default is YEStrue.

    This property is observable using key-value observing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Returns a key value coding compliant object that is used to access the user default properties.

    Declaration

    Swift

    var values: AnyObject { get }

    Objective-C

    @property(readonly, strong) id values

    Discussion

    If present the value for the property in defaults is returned, otherwise a corresponding value in initialValues is returned.

    This property is observable using key-value observing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Causes the receiver to discard any unsaved changes to bound user default properties, restoring their previous values.

    Declaration

    Swift

    func revert(_ sender: AnyObject?)

    Objective-C

    - (void)revert:(id)sender

    Discussion

    The receiver invokes discardEditing on any currently registered editors. The sender is typically the object that invoked this method.

    If appliesImmediately is YEStrue, this method only causes any bound editors with uncommitted changes to discard their edits.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Causes the receiver to discard all edits and replace the values of all the user default properties with any corresponding values in the initialValues dictionary.

    Declaration

    Swift

    func revertToInitialValues(_ sender: AnyObject?)

    Objective-C

    - (void)revertToInitialValues:(id)sender

    Discussion

    This effectively sets the preferences that a user can change to their “out-of-the-box” values. This method has no effect if initial values were not specified. The sender is typically the object that invoked this method.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Saves the values of the receiver’s user default properties.

    Declaration

    Swift

    func save(_ sender: AnyObject?)

    Objective-C

    - (void)save:(id)sender

    Discussion

    This method has no effect if appliesImmediately returns YEStrue.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.3 and later.