API  0.9.10
CPUserDefaults Class Reference

#import <CPUserDefaults.h>

+ Inheritance diagram for CPUserDefaults:

Instance Methods

(CPArray) - arrayForKey:
 
(BOOL) - boolForKey:
 
(CPData- dataForKey:
 
(CPDictionary- dictionaryForKey:
 
(void) - domainDidChange:
 
(double) - doubleForKey:
 
(float) - floatForKey:
 
(id) - init
 
(int) - integerForKey:
 
(id) - objectForKey:
 
(id) - objectForKey:inDomain:
 
(CPArray) - persistentDomainNames
 
(CPUserDefaultsStore- persistentStoreForDomain:
 
(void) - registerDefaults:
 
(void) - registerDefaultsFromContentsOfFile:
 
(void) - reloadDataFromStoreForDomain:
 
(void) - removeObjectForKey:
 
(void) - removeObjectForKey:inDomain:
 
(void) - setBool:forKey:
 
(void) - setDouble:forKey:
 
(void) - setFloat:forKey:
 
(void) - setInteger:forKey:
 
(void) - setObject:forKey:
 
(void) - setObject:forKey:inDomain:
 
(CPUserDefaultsStore- setPersistentStoreClass:forDomain:reloadData:
 
(void) - setURL:forKey:
 
(CPArray) - stringArrayForKey:
 
(CPString- stringForKey:
 
(void) - synchronize
 
(CPURL- URLForKey:
 
(CPArray) - volatileDomainNames
 
- Instance Methods inherited from CPObject
(void) - addObserver:forKeyPath:options:context:
 
(void) - applyChange:toKeyPath:
 
(id) - autorelease
 
(id) - awakeAfterUsingCoder:
 
(void) - awakeFromCib
 
(void) - bind:toObject:withKeyPath:options:
 
(Class) - classForCoder
 
(Class) - classForKeyedArchiver
 
(CPString- className
 
(id) - copy
 
(void) - dealloc
 
(CPString- description
 
(CPDictionary- dictionaryWithValuesForKeys:
 
(void) - didChange:valuesAtIndexes:forKey:
 
(void) - didChangeValueForKey:
 
(void) - didChangeValueForKey:withSetMutation:usingObjects:
 
(void) - doesNotRecognizeSelector:
 
(CPArray) - exposedBindings
 
(id) - forwardingTargetForSelector:
 
(void) - forwardInvocation:
 
(unsigned) - hash
 
(BOOL) - implementsSelector:
 
(CPDictionary- infoForBinding:
 
(BOOL) - isEqual:
 
(BOOL) - isKindOfClass:
 
(BOOL) - isMemberOfClass:
 
(BOOL) - isProxy
 
(IMP) - methodForSelector:
 
(CPMethodSignature) - methodSignatureForSelector:
 
(id) - mutableArrayValueForKey:
 
(id) - mutableArrayValueForKeyPath:
 
(id) - mutableCopy
 
(id) - mutableSetValueForKey:
 
(id) - mutableSetValueForKeyPath:
 
(id) - performSelector:
 
(id) - performSelector:withObject:
 
(void) - performSelector:withObject:afterDelay:
 
(void) - performSelector:withObject:afterDelay:inModes:
 
(id) - performSelector:withObject:withObject:
 
(id) - performSelector:withObjects:
 
(void) - release
 
(void) - removeObserver:forKeyPath:
 
(id) - replacementObjectForArchiver:
 
(id) - replacementObjectForCoder:
 
(id) - replacementObjectForKeyedArchiver:
 
(BOOL) - respondsToSelector:
 
(id) - retain
 
(id) - self
 
(void) - setValue:forKey:
 
(void) - setValue:forKeyPath:
 
(void) - setValue:forUndefinedKey:
 
(void) - setValuesForKeysWithDictionary:
 
(CPString- UID
 
(void) - unbind:
 
(Class) - valueClassForBinding:
 
(id) - valueForKey:
 
(id) - valueForKeyPath:
 
(id) - valueForUndefinedKey:
 
(void) - willChange:valuesAtIndexes:forKey:
 
(void) - willChangeValueForKey:
 
(void) - willChangeValueForKey:withSetMutation:usingObjects:
 

Class Methods

(void) + resetStandardUserDefaults
 
(id) + standardUserDefaults
 
- Class Methods inherited from CPObject
(BOOL) + accessInstanceVariablesDirectly
 
(id) + alloc
 
(id) + allocWithCoder:
 
(BOOL) + automaticallyNotifiesObserversForKey:
 
(void) + cancelPreviousPerformRequestsWithTarget:
 
(void) + cancelPreviousPerformRequestsWithTarget:selector:object:
 
(Class) + class
 
(BOOL) + conformsToProtocol:
 
(void) + exposeBinding:
 
(void) + initialize
 
(IMP) + instanceMethodForSelector:
 
(BOOL) + instancesImplementSelector:
 
(BOOL) + instancesRespondToSelector:
 
(BOOL) + isBindingExclusive:
 
(BOOL) + isSubclassOfClass:
 
(CPSet) + keyPathsForValuesAffectingValueForKey:
 
(void) + load
 
(id) + new
 
(void) + object:performSelector:withObject:afterDelay:inModes:
 
(void) + setVersion:
 
(Class) + superclass
 
(int) + version
 

Detailed Description

CPUserDefaults provides a way of storing a list of user preferences. Everything you store must be CPCoding compliant because it is stored as CPData.

Unlike in Cocoa, CPUserDefaults is per-host by default because of the method of storage. By default, the localStorage API will be used if the browser supports it. Otherwise a cookie fallback mechanism is utilized. Be aware that if the user erases the local database or clears their cookies, all the preferences will be lost. Also be aware that this is not a safe storage method; do not store sensitive data in the defaults database.

The storage method utilized is determined by matching the writing domain to a dictionary of stores, concrete subclasses of the CPUserDefaultsStore abstract class. This is a deviation from Cocoa. You can create a custom defaults store by subclassing the abstract class and implementing the protocol. Currently the protocol consists of only two methods: -data and -setData:. The latter needs to store the passed in CPData object in your storage mechanism and the former needs to return an equivalent CPData object synchronously. You can then configure CPUserDefaults to use your storage mechanism using -setPersistentStoreClass:forDomain:reloadData:

Definition at line 2 of file CPUserDefaults.h.

Method Documentation

◆ arrayForKey:()

- (CPArray) arrayForKey: (CPString aKey
implementation

Returns the array value associated with the specified key.

Definition at line 374 of file CPUserDefaults.j.

◆ boolForKey:()

- (BOOL) boolForKey: (CPString aKey
implementation

Returns the Boolean value associated with the specified key.

Definition at line 386 of file CPUserDefaults.j.

◆ dataForKey:()

- (CPData) dataForKey: (CPString aKey
implementation

Returns the data object associated with the specified key.

Definition at line 399 of file CPUserDefaults.j.

◆ dictionaryForKey:()

- (CPDictionary) dictionaryForKey: (CPString aKey
implementation

Returns the Boolean value associated with the specified key.

Definition at line 411 of file CPUserDefaults.j.

◆ domainDidChange:()

- (void) domainDidChange: (CPString aDomain
implementation

Definition at line 341 of file CPUserDefaults.j.

◆ doubleForKey:()

- (double) doubleForKey: (CPString aKey
implementation

Returns the double value associated with the specified key.

Definition at line 453 of file CPUserDefaults.j.

◆ floatForKey:()

- (float) floatForKey: (CPString aKey
implementation

Returns the float value associated with the specified key.

Definition at line 423 of file CPUserDefaults.j.

◆ init()

- (id) init
implementation

Initializes the receiver

Returns
the initialized receiver

Reimplemented from CPObject.

Definition at line 87 of file CPUserDefaults.j.

◆ integerForKey:()

- (int) integerForKey: (CPString aKey
implementation

Returns the integer value associated with the specified key.

Definition at line 438 of file CPUserDefaults.j.

◆ objectForKey:()

- (id) objectForKey: (CPString aKey
implementation

Return a default value. The order of domains in the search list is: CPRegistrationDomain, CPGlobalDomain, CPApplicationDomain, CPArgumentDomain. Calling this method may cause the search list to be recreated if any new values have recently been set. Be aware of the performance ramifications.

Definition at line 127 of file CPUserDefaults.j.

◆ objectForKey:inDomain:()

- (id) objectForKey: (CPString aKey
inDomain: (CPString aDomain 
implementation

Return a default value from a specific domain. If you know which domain you'd like to use you should always use this method because it doesn't have to hit the search list.

Definition at line 148 of file CPUserDefaults.j.

◆ persistentDomainNames()

- (CPArray) persistentDomainNames
implementation

Returns an array of currently persistent domain names.

Definition at line 285 of file CPUserDefaults.j.

◆ persistentStoreForDomain:()

- (CPUserDefaultsStore) persistentStoreForDomain: (CPString aDomain
implementation

Returns the currently used instance of CPUserDefaultStore concrete subclass for the given domain name.

Definition at line 293 of file CPUserDefaults.j.

◆ registerDefaults:()

- (void) registerDefaults: (CPDictionary aDictionary
implementation

Adds the contents the specified dictionary to the registration domain.

If there is no registration domain, one is created using the specified dictionary, and CPRegistrationDomain is added to the end of the search list. The contents of the registration domain are not written to disk; you need to call this method each time your application starts. You can place a plist file in the application's Resources directory and call registerDefaultsWithContentsOfFile:

Parameters
aDictionaryThe dictionary of keys and values you want to register.

Definition at line 213 of file CPUserDefaults.j.

◆ registerDefaultsFromContentsOfFile:()

- (void) registerDefaultsFromContentsOfFile: (CPURL aURL
implementation

This is just a convenience method to load a plist resource and register all the values it contains as defaults.

NOTE: This sends a synchronous request. If you don't want to do that, create a dictionary any way you want (including loading a plist) and pass it to -registerDefaults:

Definition at line 232 of file CPUserDefaults.j.

◆ reloadDataFromStoreForDomain:()

- (void) reloadDataFromStoreForDomain: (CPString aDomain
implementation

Definition at line 325 of file CPUserDefaults.j.

◆ removeObjectForKey:()

- (void) removeObjectForKey: (CPString aKey
implementation

Removes the value of the specified default key in the standard application domain. Removing a default has no effect on the value returned by the objectForKey: method if the same key exists in a domain that precedes the standard application domain in the search list.

Definition at line 183 of file CPUserDefaults.j.

◆ removeObjectForKey:inDomain:()

- (void) removeObjectForKey: (CPString aKey
inDomain: (CPString aDomain 
implementation

Removes the value of the specified default key in the specified domain.

Definition at line 191 of file CPUserDefaults.j.

◆ resetStandardUserDefaults()

+ (void) resetStandardUserDefaults
implementation

Synchronizes any changes made to the shared user defaults object and releases it from memory. A subsequent invocation of standardUserDefaults creates a new shared user defaults object with the standard search list.

Definition at line 76 of file CPUserDefaults.j.

◆ setBool:forKey:()

- (void) setBool: (BOOL)  aValue
forKey: (CPString aKey 
implementation

Sets the value of the specified default key to the specified Boolean value. A cast will be attempted with -boolValue.

Definition at line 511 of file CPUserDefaults.j.

◆ setDouble:forKey:()

- (void) setDouble: (double)  aValue
forKey: (CPString aKey 
implementation

Sets the value of the specified default key to the double value.

Definition at line 532 of file CPUserDefaults.j.

◆ setFloat:forKey:()

- (void) setFloat: (float)  aValue
forKey: (CPString aKey 
implementation

Sets the value of the specified default key to the specified float value. A cast will be attempted with -floatValue and parseFloat().

Definition at line 521 of file CPUserDefaults.j.

◆ setInteger:forKey:()

- (void) setInteger: (int)  aValue
forKey: (CPString aKey 
implementation

Sets the value of the specified default key to the specified integer value. A cast will be attempted with -intValue and parseInt().

Definition at line 541 of file CPUserDefaults.j.

◆ setObject:forKey:()

- (void) setObject: (id)  anObject
forKey: (CPString aKey 
implementation

Set a default value in your application domain.

Definition at line 138 of file CPUserDefaults.j.

◆ setObject:forKey:inDomain:()

- (void) setObject: (id)  anObject
forKey: (CPString aKey
inDomain: (CPString aDomain 
implementation

Set a default value in the domain you pass in. If the domain is CPApplicationDomain or CPGlobalDomain, the defaults store will eventually be persisted. You can call -forceFlush to force a persist.

Definition at line 162 of file CPUserDefaults.j.

◆ setPersistentStoreClass:forDomain:reloadData:()

- (CPUserDefaultsStore) setPersistentStoreClass: (Class)  aStoreClass
forDomain: (CPString aDomain
reloadData: (BOOL)  aFlag 
implementation

Set the CPUserDefaultStore concrete subclass that should be instantiated for use in persisting the given domain name.

Parameters
aStoreClassThe concrete subclass of CPUserDefaultsStore to use to store the defaults database for this domain
aDomainThe name of the domain for which you want to change the storage mechanism
reloadDataEmpty the cached defaults for this domain and reload them from the new storage mechanism

Definition at line 306 of file CPUserDefaults.j.

◆ setURL:forKey:()

- (void) setURL: (CPURL aValue
forKey: (CPString aKey 
implementation

Sets the value of the specified default key to the specified URL. The adjustments made in Cocoa are not present here.

Definition at line 553 of file CPUserDefaults.j.

◆ standardUserDefaults()

+ (id) standardUserDefaults
implementation

Returns the shared defaults object.

Definition at line 64 of file CPUserDefaults.j.

◆ stringArrayForKey:()

- (CPArray) stringArrayForKey: (CPString aKey
implementation

Returns the string array value associated with the specified key.

Definition at line 477 of file CPUserDefaults.j.

◆ stringForKey:()

- (CPString) stringForKey: (CPString aKey
implementation

Returns the string value associated with the specified key.

Definition at line 461 of file CPUserDefaults.j.

◆ synchronize()

- (void) synchronize
implementation

Force write out of defaults database immediately.

Definition at line 352 of file CPUserDefaults.j.

◆ URLForKey:()

- (CPURL) URLForKey: (CPString aKey
implementation

Returns the CPURL value associated with the specified key.

Definition at line 493 of file CPUserDefaults.j.

◆ volatileDomainNames()

- (CPArray) volatileDomainNames
implementation

Returns an array of currently volatile domain names.

Definition at line 277 of file CPUserDefaults.j.


The documentation for this class was generated from the following files: