Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/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
Cocoa touch 如何使用NSPredicate从核心数据实体筛选NSDate_Cocoa Touch_Cocoa_Core Data_Nspredicate_Fetch - Fatal编程技术网

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执行提取