I used to use NSCountResultType
to count entities in my CoreData contexts. A while ago I encountered countForFetchRequest:error:
which seems to do the same thing with just another (more readable) syntax.
Is there any difference between these two in terms of performance, memory management or other aspects despite the syntax?
There seems to be no difference at all (only that one returns an NSUInteger
and the other returns an NSArray
containing an NSNumber
).
Setting the launch argument
-com.apple.CoreData.SQLDebug 3
reveals that both
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Event"];
NSUInteger count = [context countForFetchRequest:request error:NULL];
and
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Event"];
[request setResultType:NSCountResultType];
NSArray *result = [context executeFetchRequest:request error:NULL];
execute exactly the same SQLite statement
SELECT COUNT( DISTINCT t0.Z_PK) FROM ZEVENT t0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With