このコードは iOS 6 では問題なく動作しますが、iOS 5 では結果が返されません。日付はカテゴリ メソッドで今日に設定されます。誰かが奇妙な何かを見つけることができますか?ありがとう!
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"KSJob"];
NSLog(@"today: %@", [NSDate today]);
// We only want to show upcoming jobs.
[fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"scheduledOn > %@", [NSDate today]]];
fetchRequest.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"scheduledOn" ascending:YES]];
self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:[(id)[[UIApplication sharedApplication] delegate]managedObjectContext] sectionNameKeyPath:@"dateToStringForSectionTitles"
cacheName:@"UpcomingJobs"];
self.fetchedResultsController.delegate = self;
NSDate カテゴリ メソッド:
+ (NSDate*) today
{
NSCalendar *cal = [NSCalendar currentCalendar];
NSDateComponents *components = [cal components:( NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit ) fromDate:[[NSDate alloc] init]];
components.timeZone = [NSTimeZone localTimeZone];
components.hour = 0;
components.minute = 0;
NSDate *today = [cal dateByAddingComponents:components toDate:[[NSDate alloc] init] options:0];
return today;
}