This will be an organic list of gotchya’s and nice-to-know tips for working with CloudKit and CoreDate. These tips are based on common questions we see from the Slack community or our own development.
You cannot query nil with NSPredicate
It is really frustrating to me that you cannot query for nil on a property.
// You would expect to be able to do something like: NSPredicate(format: "myProperty != nil") // But it returns error: Expected constant value in comparison expression: myProperty != nil
Instead, you will probably want to either filter results or do some regex matching. Ugh.
Query All (or SELECT * equivalent)
let predicate = NSPredicate(value: true)
Don’t use CloudKit as a primary data store
I recently built an app entirely around CloudKit simply to get an MVP published as quick as possible. While some apps do slip through, Apple will likely reject your application if it relies entirely on CloudKit without some sort of local data storage. From Apple’s own guidelines:
Important: How CloudKit uses records and the ability to create relationships between records should not be misconstrued. CloudKit is not a way to store data locally. It is a service for moving data to and from iCloud and is not meant to replace your app’s existing data model objects. The objects of this framework complement your existing data objects by providing a way to package your data for iCloud and receive updates to that data later.