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