[Previous] [Up] [Next]

NSUserDefaults

Authors

Richard Frith-Macdonald

Version: $Revision$

Date: $Date$

NSUserDefaults

NSUserDefaults

Declared in: Foundation/NSUserDefaults.h

Inherits from: NSObject

Conforms to: NSObject


NSUserDefaults provides an interface to the defaults system, which allows an application access to global and/or application specific defualts set by the user. A particular instance of NSUserDefaults, standardUserDefaults, is provided as a convenience. Most of the information described below pertains to the standardUserDefaults. It is unlikely that you would want to instantiate your own userDefaults object, since it would not be set up in the same way as the standardUserDefaults.

Defaults are managed based on domains. Certain domains, such as NSGlobalDomain, are persistant. These domains have defaults that are stored externally. Other domains are volitale. The defaults in these domains remain in effect only during the existance of the application and may in fact be different for applications running at the same time. When asking for a default value from standardUserDefaults, NSUserDefaults looks through the various domains in a particular order.

NSArgumentDomain
Contains defaults read from the arguments provided to the application at startup. Volitile.
Application (name of the current process)
Application specific defaults, such as window positions. Persistant.
NSGlobalDomain
Global defaults. Persistant.
Language (name based on users's language)
Constants that help with localization to the users's language. Volitle
NSRegistrationDomain
Temporary defaults set up by the application. Volitile.

The NSLanguages default value is used to set up the constants for localization. GNUstep will also look for the LANGUAGES environment variable if it is not set in the defaults system. If it exists, it consists of an array of languages that the user prefers. At least one of the languages should have a corresponding localization file (typically located in the Languages directory of the GNUstep resources).

As a special extension, on systems that support locales (e.g. GNU/Linux and Solaris), GNUstep will use information from the user specified locale, if the NSLanguages default value is not found. Typically the locale is specified in the environment with the LANG environment variable.

Instance Variables

Methods


Class Methods

resetStandardUserDefaults

+ (void) resetStandardUserDefaults;
Resets the shared user defaults object to reflect the current user ID. Needed by setuid processes whiich change the user they are running as.

standardUserDefaults

+ (NSUserDefaults*) standardUserDefaults;
Returns a shared instance of the class containing the standard defaults for the process.

userLanguages

+ (NSArray*) userLanguages;
Standards: GNUstep NotMacOS-X NotOpenStep
Returns the array of user languages preferences. Uses the NSLanguages user default if available, otherwise tries to infer setup from operating system information etc (in particular, uses the LANGUAGES environment variable).

setUserLanguages:

+ (void) setUserLanguages: (NSArray*)languages;
Standards: GNUstep NotMacOS-X NotOpenStep
Sets the array of user languages preferences. Places the specified array in the NSLanguages user default.

Instances Methods

arrayForKey:

- (NSArray*) arrayForKey: (NSString*)defaultName;
Looks up a value for a specified default, checks that it is an array. Returns nil if it is not.

boolForKey:

- (BOOL) boolForKey: (NSString*)defaultName;
Looks up a value for a specified default, checks that it is a boolean. Returns NO if it is not present.

dataForKey:

- (NSData*) dataForKey: (NSString*)defaultName;
Looks up a value for a specified default, checks that it is an NSData object. Returns nil if it is not.

dictionaryForKey:

- (NSDictionary*) dictionaryForKey: (NSString*)defaultName;
Looks up a value for a specified default, checks that it is an NSDictionary object. Returns nil if it is not.

dictionaryRepresentation

- (NSDictionary*) dictionaryRepresentation;

floatForKey:

- (float) floatForKey: (NSString*)defaultName;

init

- (id) init;

initWithUser:

- (id) initWithUser: (NSString*)username;

integerForKey:

- (int) integerForKey: (NSString*)defaultName;

objectForKey:

- (id) objectForKey: (NSString*)defaultName;

persistentDomainForName:

- (NSDictionary*) persistentDomainForName: (NSString*)domainName;

persistentDomainNames

- (NSArray*) persistentDomainNames;

registerDefaults:

- (void) registerDefaults: (NSDictionary*)dictionary;

removeObjectForKey:

- (void) removeObjectForKey: (NSString*)defaultName;

removePersistentDomainForName:

- (void) removePersistentDomainForName: (NSString*)domainName;

removeVolatileDomainForName:

- (void) removeVolatileDomainForName: (NSString*)domainName;

searchList

- (NSArray*) searchList;

setBool:forKey:

- (void) setBool: (BOOL)value forKey: (NSString*)defaultName;

setFloat:forKey:

- (void) setFloat: (float)value forKey: (NSString*)defaultName;

setInteger:forKey:

- (void) setInteger: (int)value forKey: (NSString*)defaultName;

setObject:forKey:

- (void) setObject: (id)value forKey: (NSString*)defaultName;

setPersistentDomain:forName:

- (void) setPersistentDomain: (NSDictionary*)domain forName: (NSString*)domainName;

setSearchList:

- (void) setSearchList: (NSArray*)array;

setVolatileDomain:forName:

- (void) setVolatileDomain: (NSDictionary*)domain forName: (NSString*)domainName;

stringArrayForKey:

- (NSArray*) stringArrayForKey: (NSString*)defaultName;

stringForKey:

- (NSString*) stringForKey: (NSString*)defaultName;

synchronize

- (BOOL) synchronize;

volatileDomainForName:

- (NSDictionary*) volatileDomainForName: (NSString*)domainName;

volatileDomainNames

- (NSArray*) volatileDomainNames;