On Apr 29, 2008, at 9:03 AM, Steve Cronin wrote:
Folks;
I want to obtain a count of instances for a specific entity in
stored in Core Data (SQLite)
In the archive I find this:
________________
FROM : mmalcolm crawford
DATE : Sun Apr 02 21:21:45 2006
On Apr 2, 2006, at 11:16 AM, Frederick C. Lee wrote:
> How do you count (or determine empty) data from a persistent store
(table)?
Execute a fetch for the entity in which you're interested, and count
the returned array.
________________
My question is: what is the most efficient fetch to pose given that
every fetch is IO.
A given entity might have a lot of records so an array COULD be an
unnecessarily large transaction...
Is there a best practice fetch for this 'get a count' purpose?
In Tiger that was the best means available, but if you're targeting
Leopard there is a better option available:
Create your fetch request to fetch all instances of a given entity and
execute the fetch with countForFetchRequest:error: which will simply
return the number of instances/rows that match your query.
request = [[[NSFetchRequest alloc] init] autorelease];
[request setEntity:[NSEntityDescription entityForName:@"Foo"
inManagedObjectContext:context]];
count = [context countForFetchRequest:request error:&error];
http://developer.apple.com/documentation/Cocoa/Reference/CoreDataFramework/Classes/NSManagedObjectContext_Class/Reference/Reference.html
- adam
Steve
_______________________________________________
Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
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:
http://lists.apple.com/mailman/options/cocoa-dev/aswift%40apple.com
This email sent to [EMAIL PROTECTED]
_______________________________________________
Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [EMAIL PROTECTED]