If my Author NSManagedObject model has a authorID attribute (determined by the server), will an NSFetchRequest perform better if the NSPredicate filters by authorID rather than the complete Author object? Let's say I'm fetching all Book NSManagedObjects by a certain author. Which predicateFormat is better?
[NSPredicate predicateWithFormat:@"author = %@", anAuthor]
or
[NSPredicate predicateWithFormat:@"author.authorID = %@", anAuthor.authorID]
What's the best way to profile this? I have Core Data testing working with OCUnit (SenTestingKit). Does iOS have something like Ruby's Benchmark module?
A definition of logical conditions for constraining a search for a fetch or for in-memory filtering.
You initialize an instance of NSFetchRequest as generic type: NSFetchRequest<Venue> . At a minimum, you must specify a NSEntityDescription for the fetch request. In this case, the entity is Venue . You initialize an instance of NSEntityDescription and use it to set the fetch request's entity property.
It might be worth running your app with an argument of -com.apple.CoreData.SQLDebug 1, as detailed here.
You could then see if Core Data was executing the same SQL in both circumstances (assuming you're using a SQLite store).
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