views:

32

answers:

1

Anyone know of an existing function or property that provides a count of the records in a core data entity that I'm missing in the docs?

Any help appreciated Thanks // :)

+1  A: 

I believe the best way to accomplish this is through NSManagedObjectContext's countForFetchRequest:error:

It works just like a regular fetch request, except that it only returns the count and presumably could therefore be more optimized.

Matt B.
It is definitely more optimized.
Marcus S. Zarra
@Marcus: Yeah, the reason I hedged there is simply because I haven't used all the backing stores and it's possible that there'd be one where there's no shortcut available for the count.
Matt B.
Count is always more efficient even on an xml store (the least performant store) because it is not constructing objects as a result of the fetch.
Marcus S. Zarra