views:

329

answers:

2

I am trying to get the number of rows for a given request. The only obvious way I've found to accomplish it is:

NSManagedObjectContext *context;
NSFetchRequest *request;

  ...

NSInteger count = [[context executeFetchRequest:request error:&error] count];

This seems wasteful to me, building an entire array of a large database's objects, just to find out how many there are. Is there a better way to accomplish this, in a "Core Data" way?

Thanks for the help!

+1  A: 

NSManagedObjectContext has a method which evaluates the count for a fetch request:

- (NSUInteger)countForFetchRequest:(NSFetchRequest *)request error:(NSError **)error;

See the API documentation.

Jim Correia
Ah of course, thank you very much. I'm new to Core Data programming. I was scouring for something inside the request object itself.
Alex
A: 

Can you countforfetchrequest when the request has a predicate?

morgs32
If you have a follow-up question you should better ask it as a new question, not post it as an answer. More people would see it that way and would try to solve your problem. The "Ask Question" button is in the top right.
sth