About Using iCloud with Core Data
Describes how to use iCloud with Core Data.
At a Glance
When you use Core Data, you have several storage models to choose from. Using Core Data with iCloud, you have a subset of these options, as follows:
Atomic stores (for example, the binary store) load and save all of your managed objects in one go. Atomic stores work best for smaller storage requirements.
Transactional stores (for example, the SQLite store) load and save only the managed objects that you’re using and offer high–performance querying and merging. Transactional stores work best for larger, more complex storage requirements.
Document storage (iOS only) works best for apps designed to use a document-based design paradigm. Use document storage in combination with either an atomic or a transactional store.
When you decide on a storage model, consider the strengths of each store as well as the iCloud-specific strengths discussed below.
Use Core Data Atomic Stores for Small, Simple Storage
iCloud supports XML (OS X only) and binary atomic persistent stores. Useful for small, simple storage requirements, Core Data’s atomic-store support sacrifices merging and network efficiency for simplicity of use for when your data rarely changes. When you use iCloud with an atomic persistent store, you work directly in the ubiquity container. Binary (and XML) store files are themselves transferred to the iCloud servers; so whenever a change is made to the data, the system uploads the entire store and pushes it to all connected devices. This means that changes on one peer can overwrite changes made on the others.
iCloud treats Core Data atomic stores like any other file added to your app’s ubiquity container. You can learn more about managing files in your app’s ubiquity container in iCloud Design Guide .
Use Core Data Transactional Stores for Large, Complex Storage
Core Data provides ubiquitous persistent storage for SQLite-backed stores. Core Data takes advantage of the SQLite transactional persistence mechanism, saving and retrieving transaction logs—logs of changes—in your app’s ubiquity container. The Core Data framework’s reliability and performance extend to iCloud, resulting in dependable, fault-tolerant storage across multiple peers. Continue reading this document to learn more about how to use iCloud with an SQLite store.
(iOS Only) Use Core Data Document Stores to Manage Documents in iCloud
The UIManagedDocument class is the primary mechanism through which Core Data stores managed documents in iCloud on iOS. The UIManagedDocument class manages the entire Core Data stack for each document in a document-based app. Changes to managed documents are automatically persisted to iCloud. By default, managed documents are backed by SQLite-type persistent stores, but you can choose to use atomic stores instead. While the steps you take to integrate the UIManagedDocument class into your app differ, the model-specific guidelines and best practices you follow are generally the same. You can find additional implementation strategies and tips in Using Document Storage with iCloud .
Prerequisites
iCloud is a service that stores your app’s data in the cloud and makes it available to your users’ iCloud-enabled devices. Before using Core Data’s iCloud integration, you should read more about iCloud in iCloud Design Guide . In addition, this guide assumes a working knowledge of Core Data, a powerful object graph and data persistence framework. For more information about the Core Data framework, see <!--a target="_self" -->Introduction to Core Data Programming Guide<!--/a--> in Core Data Programming Guide .
Next
Copyright © 2017 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2017-06-06