0
我想檢查2 NSDate
s他們是在同一天(時間可能不同)。 什麼我現在是這樣的:NSPredicate for checking the same date
- (NSPredicate*) predicateWithDate:(NSDate *)date {
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *components = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit) fromDate:date];
//create a date with these components
NSDate *startDate = [calendar dateFromComponents:components];
[components setMonth:0];
[components setDay:1];
[components setYear:0];
NSDate *endDate = [calendar dateByAddingComponents:components toDate:startDate options:0];
return [NSPredicate predicateWithFormat:@"((ANY notes.date >= %@) AND (ANY notes.date < %@))",startDate,endDate];
}
感謝這麼詳細的解答! 我檢查並得到一個異常「終止應用程序由於未捕獲異常'NSInvalidArgumentException',原因:'無法解析格式字符串」SUBQUERY(注意,$ n,$ n.date> =%@ AND $ n.date < [email protected]).count > 0 「'」「 – Shmidt
@Shmidt:哎呀,'count'應該是'@ count',在回答中固定 –
我試着更新了兩遍以上的代碼並清理了項目,但它仍然顯示相同的異常 – Shmidt