NSPredicate时间间隔
我有一个表有4个字段startdate,enddate,starttime和endtime。 我需要设置一些谓词
if startdate<= currentdate and currentdate <= enddate if starttime <= currenttime and endtime <= endtime else starttime <= currenttime and currenttime<= 23.00 or 0.00 <= currentime and currentime <= endtime
我如何设置谓词这种types的条件。当前date和当前时间是我的系统时间gmt。
你可以使用NSCompoundPredicate
创buildNSMutableArray
来保存你的谓词及其条件
NSMutableArray *conditions = [NSMutableArray array];
build立你的条件,并将其添加到这个数组
[conditions addObject:[NSPredicate predicateWithFormat:@"startdate <= %@ AND enddate <= %@",[NSDate date],[NSDate date]]];
添加尽可能多的条件,只要你喜欢。 最后build立你的NSCompoundPredicate
NSPredicate *predicate = [NSCompoundPredicate andPredicateWithSubpredicates:conditions];
如果你的startdate
和enddate
是NSDate
格式,你也可以访问它的时间组件,不需要单独的开始时间和endtime
只需比较两个date,就可以了。
- RestKit对象映射:使用setObjectMapping的困难:forResourcePathPattern:withFetchRequestBlock
- 查看或从设备中检索Core Data .sqlite文件
- NSFetchedResultsController XCode 7问题
- 保存更新的Core Data实例
- 核心数据与SQLite
- 核心数据映射模型版本哈希与源模型版本哈希不匹配
- 在一个TableView中使用2个FRC并configurationFRCDelegate
- iOS CoreData NSPredicate一次查询多个属性
- UIDocument openWithCompletionHandler:崩溃