NSPredicate里面如何添加NSDate进行筛选?

来源:互联网 发布:java.util.map 编辑:程序博客网 时间:2024/07/24 02:45
类似于下面这样:日期在十天之内:
NSDate *endDate = [[NSDate date] retain];NSTimeInterval timeInterval= [endDate timeIntervalSinceReferenceDate];timeInterval -=3600*24*10;NSDate *beginDate = [[NSDate dateWithTimeIntervalSinceReferenceDate:timeInterval] retain];//对coredata进行筛选(假设有fetchRequest)NSPredicate *predicate_date =[NSPredicate predicateWithFormat:@"date >= %@ AND date <= %@", beginDate,endDate];[fetchRequest setPredicate:predicate_date];//释放retained的对象[endDate release];[beginDate release];