的基礎核心數據實體,我對核心數據的實體,稱爲信息和所謂的「日期」的屬性,是字符串類型。我希望能夠給實體的日期的方式,排序在一個合適的日期格式。目前,「日期」是格式「MM/DD/YY」的字符串。如何適當地格式化字符串並執行分類。如何排序日期鍵
這是我現在的代碼片段:
- (NSFetchedResultsController *)fetchedResultsController
{
AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [delegate managedObjectContext];
NSFetchRequest *fetchRequest1 = [NSFetchRequest fetchRequestWithEntityName:@"Info"];
NSSortDescriptor *sort = [[NSSortDescriptor alloc]initWithKey:@"date" ascending:NO];
[fetchRequest1 setSortDescriptors:@[sort]];
NSError *error0 =nil;
NSArray *results = [context executeFetchRequest:fetchRequest1 error:&error0];
fetchedObjects2 = results;
[fetchRequest1 setFetchBatchSize:20];
if (_fetchedResultsController != nil)
_fetchedResultsController = nil;
NSFetchedResultsController *theFetchedResultsController =
[[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest1
managedObjectContext:context sectionNameKeyPath:nil
cacheName:nil];
self.fetchedResultsController = theFetchedResultsController;
fetchedResultsController.delegate = self;
return fetchedResultsController;
}
這顯示在表中。
- (void)reloadTableViewData
{
NSError *error;
if (![[self fetchedResultsController0] performFetch:&error]) {
// Update to handle the error appropriately.
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
exit(-1); // Fail
}
[TableView reloadData];
[self.view setNeedsDisplay];
}
這是實體: