Back user interfaces with a local replica of a CloudKit private database.
- Core Data
Use Core Data with CloudKit to give users seamless access to the data in your app across all their devices.
Core Data with CloudKit combines the benefits of local persistence with cloud backup and distribution. Core Data provides powerful object graph management features for developing an app with structured data. CloudKit lets users access their data across every device on their iCloud account, while serving as an always-available backup service.
Determine If Your App Is Eligible for Core Data with CloudKit
Apps adopting Core Data can use Core Data with CloudKit as long as the persistent store is an
NSSQLite store, and the data model is compatible with CloudKit limitations. For example, CloudKit does not support unique constraints, undefined attributes, or required relationships.
Apps using CloudKit cannot use Core Data with CloudKit with existing CloudKit containers. To fully manage all aspects of data mirroring, Core Data owns the CloudKit schema created from the Core Data model. Existing CloudKit containers aren’t compatible with this schema. If your app already uses CloudKit, you can add Core Data with CloudKit when synchronizing a Core Data store with a new container. For more information about working with multiple stores, see Manage Multiple Stores.
For more information about data model requirements, see Design a CloudKit-Compatible Core Data Model.
Set Up Your Development Environment
You need an Apple Developer Program account to access the CloudKit service and your team’s CloudKit containers during development.
You also need an iCloud account to save records to a CloudKit container. Core Data with CloudKit uses a specific record zone in the CloudKit private database, which is accessible only to the current user.
You can run and test Core Data with CloudKit apps using Simulator. You may also test with multiple physical devices logged into the same iCloud account. Connect all devices to a stable wireless internet connection to avoid network problems that could hinder synchronization.
For more information, see Create an iCloud Account for Development.
Configure Core Data with CloudKit
Add Core Data with CloudKit to your project as follows:
Design your Core Data model, and use it to initialize the CloudKit schema. See Creating a Core Data Model for CloudKit.
Modify your views to incorporate remote store changes at appropriate times. See Syncing a Core Data Store with CloudKit.
Finally, if you are building custom features or writing a web app, discover how to work with the generated CloudKit schema in Reading CloudKit Records for Core Data.