Chapter 21. Cloud
21.0. Introduction
One of the really great frameworks in the iOS SDK is CloudKit. Using this framework, you can store public and private information on the cloud with ease. One of the key concepts in CloudKit is containers, which are virtual boxes that encapsulate public and private databases.
Before I go into more details about all this jargon, let’s imagine a
simple scenario. Your app is running on an iOS device and the owner of
that device has an iCloud account already set up for herself. Every app
that runs on that device has its own CloudKit container and multiple apps
can share containers if they are set up in a specific way. Your default
container is your app’s own container, but you can find a container for
another app if you know its unique identifier in the cloud. Containers are
represented by the CKContainer
class in
CloudKit.
Every container (and therefore every app that uses a container) has two databases: one public and the other private. When you use the private database and store information there, the information is saved in the user’s iCloud account and is private to her on that device for your app. If you use the public database, the user doesn’t need an iCloud account to be able to read that information. So all users of your app can use information from the public database.
Note
Information that is stored in the public database for your app counts against your iCloud storage quota, so be very careful about tracking its size. The information stored ...
Get iOS 8 Swift Programming Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.