【发布时间】:2011-11-12 03:02:19
【问题描述】:
我现在有 5 个获取的结果控制器,并且正在添加我的第一个以实际处理数据,而不仅仅是显示它。我希望控制器最多可以管理 150 个对象。我应该选择多大的批量以一次最多处理 5 个对象?是 5 吗?
- (NSFetchedResultsController *)estimatorEventsController
{
if (__estimatorEventsController != nil)
{
return __estimatorEventsController;
}
/*
Set up the fetched results controller.
*/
// Create the fetch request for the entity.
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
// Edit the entity name as appropriate.
NSEntityDescription *entity = [NSEntityDescription entityForName:@"EstimatorEvent" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];
// Set the batch size to a suitable number.
[fetchRequest setFetchBatchSize:36];
// Edit the sort key as appropriate.
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"epoch" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
// Edit the section name key path and cache name if appropriate.
// nil for section name key path means "no sections".
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:@"EstimatorEvents"];
aFetchedResultsController.delegate = self;
self.estimatorEventsController = aFetchedResultsController;
NSError *error = nil;
if (![self.estimatorEventsController performFetch:&error])
{
NSLog(@"Unresolved error __remindersController %@, %@", error, [error userInfo]);
// abort();
}
return __estimatorEventsController;
}
感谢您的帮助!
【问题讨论】:
标签: objective-c core-data ios5 iphone-4 nsfetchedresultscontroller