Framework

CloudKit

Store structured app and user data in iCloud containers that can be shared by all users of your app.

Overview

The CloudKit framework provides interfaces for moving data between your app and your iCloud containers. You use CloudKit to take your app’s existing data and store it in the cloud so that the user can access it on multiple devices. You can also store data in a public area where all users can access it.

Using the CloudKit Framework

CloudKit is not a replacement for your app’s existing data objects. Instead, CloudKit provides complementary services for managing the transfer of data to and from iCloud servers. Because it provides minimal offline caching support, CloudKit relies on the presence of the network and optionally a valid iCloud account. (A valid iCloud account is required only when you want to save data that is specific to a single user.) Apps can always store data in a public area that is readable by all users.

Records are at the heart of all data transactions in CloudKit. A record is a dictionary of key-value pairs that represents the data you want to save. You can add new keys and values to records at any time, and you can create links between related records to organize your data. The CKRecord class defines the interfaces for managing the contents of records. CloudKit also relies heavily on the use of NSOperation objects to manage the asynchronous transfer of data to and from the server.

Topics

Records

At the core of the CloudKit framework lies the record. Nearly every action performed with CloudKit impacts the record object in some meaningful way.

CKRecord

A dictionary of key-value pairs that you use to fetch and save your app's data.

CKRecordZone

The definition of a custom area for organizing related records in a database.

CKReference

A reference used to create a many-to-one relationship between records in a database.

CKRecordValue

The protocol that provides strong type checking for objects that the CloudKit framework stores on the server.

Record Operations

Asynchronously fetch or modify records.

Assets

To keep record sizes manageable, all large elements associated with a record are stored in an asset.

CKAsset

An object representing a large file associated with a record.

Queries

Queries are used to search for records in CloudKit.

CKQueryOperation

An operation used to execute queries against a database.

CKQuery

A query that describes the criteria to apply when searching for records in a database.

CKQueryCursor

An object that marks the stopping point for a query and the starting point for retrieving the remaining results.

CKLocationSortDescriptor

An object used to sort records containing location data.

Notifications and Subscriptions

You can get information about changes on another device by subscribing to notifications.

CKQuerySubscription

The abstract base class for CloudKit subscriptions.

CKRecordZoneNotification

A notification that is triggered by changes to the contents of a record zone.

CKDatabaseNotification

A notification that is triggered by changes to the contents of a database.

Notifications

Notifications are used to inform your application of changes made by another device.

Subscription Operations

Subscriptions are used to request notifications of specific subsets of data changes.

Shared Content

In addition to making data public, you can share records with a subset of users of an app.

CKShare

A reference to a shared record.

CKShareMetadata

A reference to the metadata for a shared record.

CKShareParticipant

A reference to a person who accepted a shared record.

Share Operations

Operations are used to communicate shared information with CloudKit.

Database Management

Supporting records are a number of structures that segregate data for different purposes.

CKContainer

An encapsulation of content associated with an app.

CKDatabase

A conduit for accessing and performing operations on the data of an app container.

CKUserIdentity

A reference to a user.

CKUserIdentityLookupInfo

An object that represents information you use to fetch users.

CKApplicationPermissions

Constants indicating the permissions granted to the app by the user.

Database Operations

Operations used to look up users and maintain the state of the app's badge.

Web

While working with CloudKit, you can access data from a web browser.

CKFetchWebAuthTokenOperation

This operation fetches a web authentication token given an API token using an API token that you provide.

Errors

As with all distributed systems, it is possible to have errors occur while trying to access data in CloudKit.

CKErrorCode

Error codes that are returned by CloudKit.

CKErrorDomain

The domain for CloudKit errors. This constant is used whenever an NSError is thrown with regard to an error generated by CloudKit.

See Also