Class: NSUbiquitousKeyValueStore
Overview
Use the iCloud key-value store to make preference, configuration, and app-state data available to every instance of your app on every device connected to a user’s iCloud account. You can store scalar values such as BOOL, as well as values containing any of the property list object types: NSNumber, NSString, NSDate, NSData, NSArray, and NSDictionary.
Class Method Summary (collapse)
-
+ defaultStore
Returns the shared iCloud key-value store object.
Instance Method Summary (collapse)
-
- arrayForKey:
Returns the array associated with the specified key.
-
- boolForKey:
Returns the Boolean value associated with the specified key.
-
- dataForKey:
Returns the data object associated with the specified key.
-
- dictionaryForKey:
Returns the dictionary object associated with the specified key.
-
- dictionaryRepresentation
Returns a dictionary containing all of the key-value pairs in the key-value store.
-
- doubleForKey:
Returns the double value associated with the specified key.
-
- longLongForKey:
Returns the long long value associated with the specified key.
-
- objectForKey:
Returns the object associated with the specified key.
-
- removeObjectForKey:
Removes the value associated with the specified key from the key-value store.
-
- setArray:forKey:
Sets an array object for the specified key in the key-value store.
-
- setBool:forKey:
Sets a Boolean value for the specified key in the key-value store.
-
- setData:forKey:
Sets a data object for the specified key in the key-value store.
-
- setDictionary:forKey:
Sets a dictionary object for the specified key in the key-value store.
-
- setDouble:forKey:
Sets a double value for the specified key in the key-value store.
-
- setLongLong:forKey:
Sets a long long value for the specified key in the key-value store.
-
- setObject:forKey:
Sets an object for the specified key in the key-value store.
-
- setString:forKey:
Sets a string object for the specified key in the key-value store.
-
- stringForKey:
Returns the string associated with the specified key.
-
- synchronize
Explicitly synchronizes in-memory keys and values with those stored on disk.
Methods inherited from NSObject
#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version
Constructor Details
This class inherits a constructor from NSObject
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class NSObject
Class Method Details
+ (NSUbiquitousKeyValueStore) defaultStore
Returns the shared iCloud key-value store object. An app must always use the default iCloud key-value store object to get and set values. This store is tied to the unique identifier string your app provides in its entitlement requests.
Instance Method Details
- (Array) arrayForKey(aKey)
Returns the array associated with the specified key.
- (Boolean) boolForKey(aKey)
Returns the Boolean value associated with the specified key.
- (NSData) dataForKey(aKey)
Returns the data object associated with the specified key.
- (Hash) dictionaryForKey(aKey)
Returns the dictionary object associated with the specified key.
- (Hash) dictionaryRepresentation
Returns a dictionary containing all of the key-value pairs in the key-value store. This method returns the in-memory version of the keys and values. If you want to ensure that this dictionary contains the most recent set of changes, call synchronize shortly before calling this method.
- (Float) doubleForKey(aKey)
Returns the double value associated with the specified key.
- (Integer) longLongForKey(aKey)
Returns the long long value associated with the specified key.
- (Object) objectForKey(aKey)
Returns the object associated with the specified key. You can use this method to retrieve objects whose type you do not necessarily know from the key-value store. The object returned by this method is always one of the property list types: NSNumber, NSString, NSDate, NSData, NSArray, or NSDictionary.
- (Object) removeObjectForKey(aKey)
Removes the value associated with the specified key from the key-value store. If the specified key is not found in the key-value store, this method does nothing. This method removes the key from the in-memory version of the store only. Call the synchronize method at appropriate times to update the information on disk.
- (Object) setArray(anArray, forKey:aKey)
Sets an array object for the specified key in the key-value store.
- (Object) setBool(value, forKey:aKey)
Sets a Boolean value for the specified key in the key-value store.
- (Object) setData(aData, forKey:aKey)
Sets a data object for the specified key in the key-value store.
Using an NSData object as a value in key-value storage lets you store arbitrary data. For example, in a game app, you can use it to store game state to iCloud.Be sure to exercise caution when storing a data object. Because it is available to be read and modified by every instance of your app attached to a user’s iCloud account, some of which may be older versions or running on another platform, you must diligently protect a data object’s integrity. For more information, see “Exercise Caution When Using NSData Objects as Values” in iCloud Design Guide.
- (Object) setDictionary(aDictionary, forKey:aKey)
Sets a dictionary object for the specified key in the key-value store.
- (Object) setDouble(value, forKey:aKey)
Sets a double value for the specified key in the key-value store.
- (Object) setLongLong(value, forKey:aKey)
Sets a long long value for the specified key in the key-value store.
- (Object) setObject(anObject, forKey:aKey)
Sets an object for the specified key in the key-value store. If the type of anObject is not one of the property list types, this method does not set it in the key-value store. Instead, it logs an error and silently ignores the object.
- (Object) setString(aString, forKey:aKey)
Sets a string object for the specified key in the key-value store.
- (String) stringForKey(aKey)
Returns the string associated with the specified key.
- (Boolean) synchronize
Explicitly synchronizes in-memory keys and values with those stored on disk. The only recommended time to call this method is upon app launch, or upon returning to the foreground, to ensure that the in-memory key-value store representation is up-to-date.Changes you make to the key-value store are saved to memory. The system then synchronizes the in-memory keys and values with the local on-disk cache, automatically and at appropriate times. For example, it synchronizes the keys when your app is put into the background, when changes are received from iCloud, and when your app makes changes to a key but does not call the synchronize method for several seconds.This method does not force new keys and values to be written to iCloud. Rather, it lets iCloud know that new keys and values are available to be uploaded. Do not rely on your keys and values being available on other devices immediately. The system controls when those keys and values are uploaded. The frequency of upload requests for key-value storage is limited to several per minute. During synchronization between memory and disk, this method updates your in-memory set of keys and values with changes previously received from iCloud.