Search code examples
swiftcloudkitckquery

Swift CKQuery with multiple record types


So I'm in good shape on querying specific record types and parsing their data. What I can't figure out though is how to search across all record types for, as an example, everything that was modified today, regardless of what record type it is.

Thoughts?


Solution

  • The terms that comes to mind is TRUEPREDICATE and metadata. You can read all about them on the apple documentation page. Most of the examples are surprisingly in Objective C, but translating them to swift is easy. The one you need becomes...

    In Swift

    let predicate = NSPredicate(format: "TRUEPREDICATE") let query = CKQuery(recordType: "Blah", predicate: predicate)

    Which will fetch all records of type Blah, if you want to search multiple databases than you need to do multiple queries, one against each schema I believe.