核心数据中的所有对象
{
dtStartDate = "Jun 10, 2016-10:40 AM";
},
{
dtStartDate = "May 12, 2016-06:55 AM";
},
{
dtStartDate = "May 12, 2016-08:05 AM";
},
{
dtStartDate = "May 12, 2016-02:30 PM";
},
{
dtStartDate = "Jun 12, 2016-07:50 AM";
},
{
dtStartDate = "Jul 12, 2016-08:50 AM";
},
{
dtStartDate = "Jun 12, 2016-07:50 AM";
},
{
dtStartDate = "May 12, 2016-10:00 AM";
},
{
dtStartDate = "Jun 12, 2016-07:30 AM";
}
我使用这种日期格式来预测核心数据
NSDate *dt = [NSDate date];
NSDateFormatter *df =[[NSDateFormatter alloc] init];
[df setDateFormat:@"MMM dd, yyyy-hh:mm a"];
NSString *today =[df stringFromDate:dt];
NSDate *dateOfToday = [df dateFromString:today];
NSMutableArray *meetings=nil;
现在我有两个条件获取未来日期(包括当前)和过去的获取日期
获取未来日期(包括今天)
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"dtStartDate >= %@",dateOfToday];
NSMutableArray *meetingsArr = [[CoreDataAPI sharedInstance] checkForRecordExistInTable:@"Tbl_Meeting" withCompountPredicate:[NSArray arrayWithObjects:predicate, nil]];
返回9个对象(全部) 的 WRONG
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"dtStartDate <= %@",dateOfToday];
NSMutableArray *meetingsArr = [[CoreDataAPI sharedInstance] checkForRecordExistInTable:@"Tbl_Meeting" withCompountPredicate:[NSArray arrayWithObjects:predicate, nil]];
返回0对象(无) 的 WRONG
请先帮助我解决它
我可以使用此方法手动完成并正常工作。但我只想做谓词
-(NSMutableArray *)filterMeetingsBasedOnTime:(BOOL)isPastMtng :(NSMutableArray*)arr
{
NSDate *dt = [NSDate date];
NSDateFormatter *df =[[NSDateFormatter alloc] init];
[df setDateFormat:@"MMM dd, yyyy-hh:mm a"];
NSMutableArray *arrMeeting = [[NSMutableArray alloc] init];
for(NSDictionary *sMtngDict in arr)
{
NSDate *meetDate = [df dateFromString:[sMtngDict valueForKey:@"dtStartDate"]];
if(isPastMtng)
{
if([meetDate timeIntervalSinceDate:dt]<0)
{
[arrMeeting addObject:sMtngDict];
}
}
else{
if([meetDate timeIntervalSinceDate:dt]>=0)
{
[arrMeeting addObject:sMtngDict];
}
}
}
return arrMeeting;
}
我们可以在谓词中使用此方法逻辑,如果是,那么如何?