NSFetchedResultsController is loading all rows even through I have batch set

后端 未结 3 1434
轻奢々
轻奢々 2021-02-06 09:40

Ok. This is the exact same question as here: Why is NSFetchedResultsController loading all rows when setting a fetch batch size?

But the solution for his doesn\'t solve

3条回答
  •  星月不相逢
    2021-02-06 10:25

    I've had the same question and in the end I concluded, that it works as it should.

    When you set fetchBatchSize fetchRequest loads all data to cache because otherwise this parameter would be useless. I guess it's used for using data just after loading. But when you getting object as [fetchResultController objectAtIndexPath:indexPath] it is fulfilled by ManagedObjectContext (I suppose), not by fetchRequest.

    So you can set fetchBatchSize to 0 and every time you access fault it will be requested from persistent store. Or you can set other value and also set fetchLimit and fetchOffset every time you scroll table view. But you still have to know overall objects number.

提交回复
热议问题