Cocoa touch 如何使用NSPredicate从核心数据实体筛选NSDate
我有一个带有时间戳(Cocoa touch 如何使用NSPredicate从核心数据实体筛选NSDate,cocoa-touch,cocoa,core-data,nspredicate,fetch,Cocoa Touch,Cocoa,Core Data,Nspredicate,Fetch,我有一个带有时间戳(NSDate)的核心数据实体,我需要获取过去n天的记录。我怎么能这么做?谢谢。试试这个 #define DAY_1 86400 //seconds in one day NSFetchRequest *request=[[NSFetchRequest alloc] init]; request.entity=[NSEntityDescription entityForName:@"<your entity name>" inManagedObjectContext
NSDate
)的核心数据实体,我需要获取过去n天的记录。我怎么能这么做?谢谢。试试这个
#define DAY_1 86400 //seconds in one day
NSFetchRequest *request=[[NSFetchRequest alloc] init];
request.entity=[NSEntityDescription entityForName:@"<your entity name>" inManagedObjectContext:<your context>];
request.predicate=[NSPredicate predicateWithFormat:@"timestamp > %@",[NSDate dateWithTimeIntervalSinceNow:-DAY_1*n]];
NSFetchedResultsController *frc=[[NSFetchedResultsController alloc] initWithFetchRequest:request
managedObjectContext:<your context>
sectionNameKeyPath:nil
cacheName:nil];
[request release];
#定义日期_186400//一天中的秒数
NSFetchRequest*request=[[NSFetchRequest alloc]init];
request.entity=[NSEntityDescription entityForName:@''在托管对象上下文:];
request.predicate=[NSPredicate predicateWithFormat:@“timestamp>%@,[NSDate DateWithTimeIntervalsIncenseNow:-DAY_1*n];
NSFetchedResultsController*frc=[[NSFetchedResultsController alloc]initWithFetchRequest:请求
managedObjectContext:
sectionNameKeyPath:无
cacheName:nil];
[请求释放];
现在,您可以使用frc执行提取