Re: Counting instances in Core Data
Re: Counting instances in Core Data
- Subject: Re: Counting instances in Core Data
- From: "I. Savant" <email@hidden>
- Date: Tue, 29 Apr 2008 12:31:20 -0400
> > 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.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden