3

I want to query CloudKit for all the records with a blank date (0/00/0000 00:00:00) and I don't know how to make a predicate that will do it.

Here is what I've tried, and the associated errors:

    let predicate = NSPredicate(format: "ready == nil")                     // <ready != nil>: <nil> is not a function expression
    let predicate = NSPredicate(format: "ready == NIL")                     // <ready == nil>: <nil> is not a function expression
    let predicate = NSPredicate(format: "ready != NULL")                        // <ready != nil>: <nil> is not a function expression
    let predicate = NSPredicate(format: "ready == %@", NSNull())            // NSNull not allowed in comparison expression
    let predicate = NSPredicate(format: "ready == $NULL")                   // Unable to parse the format string "ready == $NULL"
    let predicate = NSPredicate(format: "ready == $BLANK")                  // <ready == $BLANK>: <$BLANK> is not a function expression
    let blankDate: Date = Date.init()
    let predicate = NSPredicate(format: "ready == %@", blankDate as NSDate)

    let haveADate = NSPredicate(format: "ready > %@", NSDate.distantPast as NSDate)
    let predicate = NSCompoundPredicate(notPredicateWithSubpredicate: haveADate)    // Inverting a valid one doesn't work either
garafajon
  • 1,278
  • 13
  • 15
  • After more research I believe this is not possible. According to the accepted answer here : https://stackoverflow.com/questions/32683691/how-do-i-query-for-nil-values-with-cloudkit-js CloudKit is a key-value store so if the value has not been set then the key doesn't even exist. – garafajon May 31 '17 at 14:10

1 Answers1

1

I believe your issue is similar to this one.

Instead of "ready == %@", you should try using "(ready >= %@) AND (ready <= %@)" with two reference values to compare to.

Laxus
  • 86
  • 3