简体   繁体   English

使用NSPredicate查询CloudKit以获取空白日期(或null或其他)

[英]Query CloudKit with NSPredicate for Date that is blank (or null or whatever)

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. 我想查询CloudKit以获取具有空白日期(0/00/0000 00:00:00)的所有记录,并且我不知道如何创建将执行此操作的谓词。

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

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. 而不是"ready == %@" ,你应该尝试使用"(ready >= %@) AND (ready <= %@)"与两个参考值进行比较。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM