Snowman
Snowman

Reputation: 32091

Does calling the fetchedObjects property of an NSFetchedResultsController fault all objects?

I'm trying to debug a strange problem I'm having, and I'm absolutely clueless where to begin. This question is simple though:

I have a fetch request that returns about 2000 objects, but with a batchSize of 15. So only 15 objects are loaded into memory, the rest are faulted in as they are needed. The issue I'm having is that for some reason all my objects are being faulted in immediately when the fetch request finishes. This takes about 20 seconds. I don't understand why it's happening.

It must mean I'm accessing all these objects somehow, causing them all to be faulted. Does calling fetchedResultsController.fetchedObjects.count cause all objects to be faulted by any chance?

Upvotes: 0

Views: 1062

Answers (1)

borrrden
borrrden

Reputation: 33423

The documents say this about fetchedObjects

If the fetch request has no predicate, then the results array includes all instances of the entity specified by the fetch request.

What are you trying to do? The correct way to get the count is like this:

id <NSFetchedResultsSectionInfo> sectionInfo = [controllers sections] objectAtIndex:section];

return [sectionInfo numberOfObjects];

Upvotes: 2

Related Questions