NSPredicate过滤当前时间

Chr*_*jær 2 sqlite core-data objective-c nspredicate nsfetchrequest

我正在尝试创建一个NSPredicate(用于a NSFetchRequest中的核心数据NSFetchedresultsController),根据当前时间过滤记录.

不是谓词创建的时间:

[NSPredicate predicateWithFormat:@"(criticalDate < %@)", [NSDate date]]

但是评估谓词的时间,因为我想避免一直使用新的fetchRequests更新fetchedResultsController.我正在寻找的东西(但我自己找不到)是这样的:

[NSPredicate predicateWithFormat:@"(criticalDate < ????)"]

这是为iPhone,这意味着now()不支持,所以我想无论解决方案是什么,它将是一种黑客攻击.

提前致谢

Dav*_*ong 7

你想用:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"criticalDate < now()"];
Run Code Online (Sandbox Code Playgroud)

  • @MikeAbdullah实际上,IIRC已经在iOS 8中添加了对`now()`函数的支持. (2认同)