Database Reference
In-Depth Information
Figure 4-20. Your favorite number
Key-Value Store
Now it's time to dive into iCloud using the Key-Value Store. iCloud gives us two models to work with:
the Key-Value Store and the Document Store. Let's start off with the Key-Value Store because it is
by far the most basic to implement. The iCloud Key-Value Store is very similar to the NSUserDefaults
we are already using. It is an NSDictionary in the cloud, or more precisely, iCloud.
The iCloud Key-Value Store is recommended to only be used for app preferences, app configuration,
or app state. The Key-Value store is available to every instance of your app on all the user's devices.
So, when a user updates a value on one instance of the app, the other instances will be notified of
this change and can update accordingly.
Each time you write a value to this store, the operation will either succeed or fail automatically. This
means that if you need to ensure that all the values you want to save are actually saved, you can
package them in a dictionary. If any of the values inside the dictionary fail to save, none of the values
will be saved.
iCloud automatically handles conflicts by delivering you the most up-to-date value for any keys
based on timestamp. For this reason, it is recommended that you use NSUserDefaults in concert
with iCloud Key-Value Store. This allows you to resolve any conflicts that could arise from situations
where one device may update a value before it receives the previously updated value.
 
Search WWH ::




Custom Search