CloudKit Query: After Date and Not in Array

270 views Asked by At

I'm trying to query records from CloudKit that either have a newer modificationDate than what I have locally, or perhaps that I don't have at all.

The records I have already are stored in recordNames. The the date is date.

I can do this with two predicates like this:

//Modification Date
let predicateDate = NSPredicate(format: "modificationDate > %@", date)

//Records I have already
let predicateRecordName = NSPredicate(format: "NOT (recordName IN %@)",recordNames)

//Combined 'OR'
let predicate = NSCompoundPredicate(orPredicateWithSubpredicates: [predicateDate, predicateRecordName])

But when I try to combine this as a compound OR predicate, or combine them into a single predicate, I get an error:

Invalid predicate... CKErrorDomain Code=12... is not a comparison predicate, ck_isComparisonError=true

I see in the docs that doing an OR predicate is not allowed. I'd love to not have to make two separate queries here. Any ideas on how I can pull this off?

1

There are 1 answers

0
Francesc Roig On

'OR' option not working with predicates (I don't know if this is a bug of CloudKit). You have to make multiple queries.