NSPredicate BETWEEN with NSDate causes -[__NSDate constantValue]: unrecognized selector sent to instance 0x1e7ff0

前端 未结 2 842
野性不改
野性不改 2020-12-11 03:23

I\'m trying to fetch from Core Data records that have a startTime between two dates.

Here\'s my code:

NSDate *today = [NSDate date];
NSDate *distantF         


        
2条回答
  •  萌比男神i
    2020-12-11 03:57

    According to the documentation, the BETWEEN operator counts as an aggregate expression, and ...

    Aggregate expressions are not supported by Core Data.

    So yes, in order to work around this, you must use the >= and <= construction.

    However, given that one of your dates is [NSDate distantFuture], you don't need the "less than" comparison at all. You should be able to do:

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"startTime >= %@", [NSDate date]];
    

提交回复
热议问题