Skip navigation.
 
mlRe: Counting instances in Core Data
FROM : I. Savant
DATE : Tue Apr 29 18:31:20 2008

>  >  My question is: what is the most efficient fetch to pose given that every
>  > fetch is IO.
>
>  Yes.


  Sorry, I thought this was "is this the most efficient" ... Meaning:
mmalc's response of "Execute a fetch for the entity in which you're
interested, and count the returned array." is the most efficient. It
means exactly what it says (a basic fetch for that entity will return
all instances of that entity). For the how too, see the documentation:

http://developer.apple.com/documentation/Cocoa/Conceptual/CoreData/Articles/cdFetching.html

  So a simple fetch request for all "Foo" instances:

NSFetchRequest * f = [[[NSFetchRequest alloc] init] autorelease];
[f setEntity:[NSEntityDescription entityForName:@"Foo"
inManagedObjectContext:[self managedObjectContext]]];
NSArray * results = [[self managedObjectContext] executeFetchRequest:f
error:nil];

  Obviously you wouldn't want to ignore potential errors, but ...

--
I.S.

Related mailsAuthorDate
mlCounting instances in Core Data Steve Cronin Apr 29, 18:03
mlRe: Counting instances in Core Data I. Savant Apr 29, 18:08
mlRe: Counting instances in Core Data I. Savant Apr 29, 18:31
mlRe: Counting instances in Core Data Adam Swift Apr 29, 20:18
mlRe: Counting instances in Core Data I. Savant Apr 29, 20:33
mlRe: Counting instances in Core Data Adam Swift Apr 29, 20:33
mlRe: Counting instances in Core Data Ben Trumbull Apr 29, 22:57