Counting objects returned by NSFetchedResultsController
To get the total number of objects fetched by a NSFetchedResultsController
you could do this:
NSFetchedResultsController *controller = ...
NSUInteger count = [controller.fetchedObjects count];
Which is fine… But this is better:
NSFetchedResultsController *controller = ...
[controller.sections.valueForKeyPath: @"@sum.numberOfObjects"];
Why? Because it uses the neat KVC, which is an awesome yet under used tool.
I also have the gut feeling that it’s more efficient that count
, but I’d need to run some tests to be sure about it.