Database Reference
In-Depth Information
Enabling iCloud
iCloud syncs your Core Data store using ubiquity containers . The term ubiquity is
appropriate, since it means “found everywhere.” Ubiquity containers are stored in a
special place in your application sandbox that iOS manages for you. You might have
asked NSFileManager for your app's Documents directory before; for iCloud, you'll
ask for a ubiquity container URL.
Core Data saves your app's data to the ubiquity container URL in the same way it
would save a URL pointing to the Documents directory. The difference is that the
iCloud background process will see changes to files in this special URL and begin
uploading the contents to the cloud. You have no control over when or how often
this happens—it's all managed by the operating system.
Each time you save data to a SQLite store, transaction logs contain the data
changes in these “atomic” commits. The term atomic here means all the changes in
the log are valid, or none of them are. So we can be sure that applying changes
from one log to the next, there is no data inconsistency, at least at the SQLite level.
When using iCloud with Core Data SQLite based stores, it is the syncing of these
transaction logs across the cloud, rather than the data store itself, that actually
transfer data from one device to another. This is a far safer method of merging
database changes than trying to merge the database files since the logs are
replayed in the same order they were created.
When the London Bridge was moved from spanning the river Thames in London to
span a portion of the Colorado River in Lake Havasu City, Arizona, it was
dismantled, brick by brick. Each brick was numbered and the order logged properly
as the bridge was taken apart. It was then rebuilt in the correct order using the
brick numbers as the guide. The transaction logs and their contents are the bricks
that are rebuilt on other users' devices.
To set up a ubiquity container for CloudNotes, you need to modify the app's
capabilities. In Xcode, select the CloudNotes project file and then the CloudNotes
target. From there, select the Capabilities tab at the top, and you should see the
screen below:
 
Search WWH ::




Custom Search