Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sqlite CoreData-使用时间范围(NSTimeInterval)格式化的NSPredicate_Sqlite_Nsdate - Fatal编程技术网

Sqlite CoreData-使用时间范围(NSTimeInterval)格式化的NSPredicate

Sqlite CoreData-使用时间范围(NSTimeInterval)格式化的NSPredicate,sqlite,nsdate,Sqlite,Nsdate,我试图找出如何浏览我的CoreData信息,并找到在NSTimeInterval内具有createdAt(作为NSDate的对象的一部分)的对象。我该如何设置 我查看了以下文档: 但我在那里什么也没找到 我是否需要创建两个时间戳并在两者之间使用SQL 任何帮助都会很好。首先,检查NSDate是否在NSTimeInterval内没有意义,因为NSTimeInterval只指定时间长度,而不是位置。相反,您希望使用两个单独的NSDate来指定间隔的开始和结束 下面是它的样子(开始时间和结束时间是N

我试图找出如何浏览我的CoreData信息,并找到在NSTimeInterval内具有createdAt(作为NSDate的对象的一部分)的对象。我该如何设置

我查看了以下文档:

但我在那里什么也没找到

我是否需要创建两个时间戳并在两者之间使用SQL


任何帮助都会很好。

首先,检查NSDate是否在NSTimeInterval内没有意义,因为NSTimeInterval只指定时间长度,而不是位置。相反,您希望使用两个单独的NSDate来指定间隔的开始和结束

下面是它的样子(开始时间和结束时间是NSDate)

NSFetchRequest*request=[[NSFetchRequest alloc]init];
request.entity=[NSEntityDescription entityForName:@“YourEntityName”在托管对象上下文:yourContext中];
NSPredicate*beginningPredicate=[NSPredicate predicateWithFormat:@“createdAt>=%@”,beginningTime];
NSPredicate*endPredicate=[NSPredicate predicateWithFormat:@“createdAt
NSFetchRequest *request = [[NSFetchRequest alloc] init];
request.entity = [NSEntityDescription entityForName:@"YourEntityName" inManagedObjectContext:yourContext];
NSPredicate *beginningPredicate = [NSPredicate predicateWithFormat:@"createdAt >= %@", beginningTime];
NSPredicate *endPredicate = [NSPredicate predicateWithFormat:@"createdAt <= %@", endTime];
request.predicate = [NSCompoundPredicate andPredicateWithSubpredicates:[NSArray arrayWithObjects:beginningPredicate, endPredicate, nil]];
NSArray *results = [yourContext executeFetchRequest:request error:NULL];