Inherits from | |
Conforms to | |
Framework | /System/Library/Frameworks/AppKit.framework |
Availability | Available in Mac OS X v10.3 and later. |
Companion guide | |
Declared in | NSUserDefaultsController.h |
Related sample code |
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.
– defaults
– setInitialValues:
– hasUnappliedChanges
– initialValues
– setAppliesImmediately:
– appliesImmediately
– values
– revert:
– revertToInitialValues:
– save:
Returns the shared instance of NSUserDefaultsController, creating it if necessary.
+ (id)sharedUserDefaultsController
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.
NSUserDefaultsController.h
Returns whether any changes made to bound user default properties are saved immediately.
- (BOOL)appliesImmediately
Default is YES
.
This property is observable using key-value observing.
NSUserDefaultsController.h
Returns the instance of NSUserDefaults in use by the receiver.
- (NSUserDefaults *)defaults
This property is observable using key-value observing.
NSUserDefaultsController.h
Returns whether the receiver has user default values that have not been saved to NSUserDefaults.
- (BOOL)hasUnappliedChanges
This property is observable using key-value observing.
NSUserDefaultsController.h
Returns a dictionary containing the receiver’s initial default values.
- (NSDictionary *)initialValues
These values are used when is no value found for the bound property in defaults
.
This property is observable using key-value observing.
NSUserDefaultsController.h
Returns an initialized NSUserDefaultsController object using the NSUserDefaults instance specified in defaults and the initial default values contained in the initialValues dictionary.
- (id)initWithDefaults:(NSUserDefaults *)defaults initialValues:(NSDictionary *)initialValues
If defaults is nil
, the receiver uses [NSUserDefaults standardUserDefaults]
.
This method is the designated initializer.
NSUserDefaultsController.h
Causes the receiver to discard any unsaved changes to bound user default properties, restoring their previous values.
- (void)revert:(id)sender
The receiver invokes discardEditing
on any currently registered editors. The sender is typically the object that invoked this method.
If appliesImmediately
is YES
, this method only causes any bound editors with uncommitted changes to discard their edits.
NSUserDefaultsController.h
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.
- (void)revertToInitialValues:(id)sender
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.
NSUserDefaultsController.h
Saves the values of the receiver’s user default properties.
- (void)save:(id)sender
This method has no effect if appliesImmediately
returns YES
.
NSUserDefaultsController.h
Sets whether any changes made to the receiver’s user default properties are saved immediately.
- (void)setAppliesImmediately:(BOOL)flag
The default is YES
.
NSUserDefaultsController.h
Sets the receiver’s initial values to initialValues.
- (void)setInitialValues:(NSDictionary *)initialValues
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.
NSUserDefaultsController.h
Returns a key value coding compliant object that is used to access the user default properties.
- (id)values
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.
NSUserDefaultsController.h
© 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-05-23)