This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| See: https://developer.apple.com/library/content/documentation/DataManagement/Conceptual/CloudKitQuickStart/SubscribingtoRecordChanges/SubscribingtoRecordChanges.html | |
| 01. Save Subscriptions to the Database | |
| In your code, create a subscription object specifying the record type, predicate, and types of changes you | |
| want to be notified about. Then save the subscription object to the database. | |
| To create and save a subscription | |
| A. Create a predicate object. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| See: https://developer.apple.com/library/content/documentation/DataManagement/Conceptual/CloudKitQuickStart/AddingAssetsandLocations/AddingAssetsandLocations.html | |
| 01. Store Large Files in CloudKit | |
| You can store large data files in CloudKit using the Asset field type. Assets are owned by the associated | |
| record, and CloudKit handles garbage collection for you. CloudKit also efficiently uploads and downloads | |
| assets. | |
| In code, the Asset field type is represented by a CKAsset object. This code fragment sets an Asset field | |
| in an Artwork record to a resource file. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| See: https://developer.apple.com/library/content/documentation/DataManagement/Conceptual/CloudKitQuickStart/CreatingaSchemabySavingRecords/CreatingaSchemabySavingRecords.html | |
| Improve the user’s experience by verifying that the user is signed in to their iCloud account | |
| before saving records. If the user is not signed in, present an alert instructing the user how | |
| to enter their iCloud credentials and enable iCloud Drive. | |
| Insert your code that saves records in the else clause below. | |
| CKContainer.default().accountStatus(completionHandler: {(_ accountStatus: CKAccountStatus, _ error: Error?) -> Void in | |
| if accountStatus == .noAccount { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| To run your app in iOS Simulator, enter the iCloud credentials in iOS Simulator | |
| before you select the simulator and click the Run button in Xcode. You need to | |
| perform these steps for each iOS Simulator you select in the Scheme pop-up menu in Xcode. | |
| To enter iCloud credentials in iOS Simulator | |
| Choose Xcode > Open Developer Tool > iOS Simulator. | |
| In iOS Simulator, choose Hardware > Home. | |
| Launch the Settings app and click iCloud. | |
| ../Art/3_icloud_settings_2x.png |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| See: https://developer.apple.com/library/content/documentation/DataManagement/Conceptual/CloudKitQuickStart/CreatingaSchemabySavingRecords/CreatingaSchemabySavingRecords.html | |
| See: https://developer.apple.com/library/content/documentation/DataManagement/Conceptual/CloudKitQuickStart/AddingReferences/AddingReferences.html | |
| You can use reference field types to represent both one-to-one and one-to-many relationships between | |
| your model objects. In your code, a reference field is a CKReference object that encapsulates the | |
| record ID for a target record and is added to the source record. To represent a one-to-one relationship | |
| in your schema, add a reference field to the source record type. | |
| To represent a one-to-many relationship between your model objects, it is more efficient if the reference |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| The table shows possible field types, as they appear in CloudKit Dashboard, | |
| and their equivalent CloudKit framework classes. | |
| Field Type | |
| Class | |
| Description | |
| Asset | |
| CKAsset | |
| A large file that is associated with a record but stored separately |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| You’ll need an iCloud account to save records to a CloudKit container. | |
| You’ll enter the credentials for this iCloud account on the device that you run your app. | |
| If you don’t have an iCloud account, create one that you can use during development. | |
| On your Mac, launch System Preferences and click iCloud. Click Create Apple ID under the | |
| Apple ID text field and follow the instructions. | |
| In development, when you run your app through Xcode on a simulator or a device, you need to | |
| enter iCloud credentials to read records in the public database. In production, the default | |
| permissions allow non-authenticated users to read records in the public database but do not | |
| allow them to write records. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Within the scope of an application’s cloud container, each user has a unique, application | |
| specific iCloud user ID and a user info record where the user ID is used as the record ID | |
| for the user’s info record. | |
| The record ID of the current user’s info record can be obtained via a call to the | |
| fetchUserRecordID(completionHandler:) method of the container instance. Once the record | |
| ID has been obtained, this can be used to fetch the user’s record from the cloud database: | |
| container.fetchUserRecordID(completionHandler: {recordID, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| See: https://www.whatmatrix.com/blog/a-guide-to-cloudkit-how-to-sync-user-data-across-ios-devices/ | |
| 01. Creating a Custom Zone | |
| CloudKit automatically creates a default zone for the private database. However, you can get | |
| more functionality if you use a custom zone, most notably, support for fetching incremental record changes. | |
| Since this is a first example of using an operation, here are a couple of general observations: | |
| First, all CloudKit operations have custom completion closures (and many have intermediate closures, |