objective-c - iPhone 4 iOS 5 NSFetchedResultsController 如何选择批量大小?

标签 objective-c core-data ios5 iphone-4 nsfetchedresultscontroller

我现在有 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/

相关文章:

objective-c - NSArray:删除具有重复属性的对象

ios - 如果使用 CKFetchRecordZoneChangesOperation 时应用程序被终止,会发生什么?

objective-c - Cocoa Binding 仅用于检索

ios - 从对象中检索数据

ios - 在 Storyboard中,Popoverview 不接收委托(delegate)

iphone - 关闭设备音量 - iOS

objective-c - 获取 UIManagedDocument 的 URL

ios - 在没有突变的情况下得到 "NSOrderedSetArrayProxy was mutated while being enumerated"错误

ios - UICollectionView 滚动性能不佳

ios - React Native iOS Native View 使用适当的 reactTag 发送事件