I need to write a native SQL Query while I\'m using Core Data in my project. I really need to do that, since I\'m using NSPredicate
right now and it\'s not efficien
Short answer: you can't do this.
Long answer: Core Data is not a database per se - it's not guaranteed to have anything relational backing it, let alone a specific version of SQLite that you can query against. Furthermore, going mucking around in Core Data's persistent store files is a recipe for disaster, especially if Apple decides to change the format of that file in some way. You should instead try to find better ways to optimize your usage of NSPredicate or start caching the values you care about yourself.
Have you considered using the KVC collection operators? For example, if you have an entity Foo
each with a bunch of children Bar
, and those Bar
s have a Baz
integer value, I think you can get the sum of those for each Foo
by doing something like:
foo.bars.@sum.baz
Not sure if these are applicable to predicates, but it's worth looking into.