我现在有 5 个获取结果 Controller ,并且正在添加我的第一个 Controller 来实际处理数据,而不仅仅是显示数据。我预计 Controller 最多可管理 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;
}
感谢您的帮助!
最佳答案
亚历克斯,
我的提取结果 Controller 中有 800 多个项目,并且不批量提取。不要担心 150 个项目……你知道,过早的优化等等。
要记住的另一件事是批量限制是针对获取请求而不是获取结果 Controller 。这种区别很重要,因为获取请求是较低级别的项目,可以轻松触发包含数千个项目的结果数组。处理如此规模的查询必须小心。 150 行并不是什么大问题。
安德鲁
关于objective-c - iPhone 4 iOS 5 NSFetchedResultsController 如何选择批量大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8102224/