0

What is more efficient?

  1. Using predicate with "IN" like [NSPredicate predicateWithFormat:@"myObjectId in %@", neededIds] ;
  2. Creating bunch of predicates for each id like ([NSPredicate predicateWithFormat:@"myObjectId == neededIds[i]"]) and then using this predicates to create compound predicate like [NSPredicate orPredicateWithSubpredicates:perIdPredicates]?

I'd prefer first case, because it seems much cleaner, less code, but my collegue insist that second case with compound predicate is more efficient (but I never heard about it in WWDCs).

Vladlex
  • 845
  • 8
  • 16
  • You could check it yourself: Enable Core Data SQL debugging (http://stackoverflow.com/questions/6428630/xcode4-and-core-data-how-to-enable-sql-debugging) and you'll see all the SQLite queries and the timing. – Martin R Mar 31 '15 at 19:15
  • As Martin says, chek it yourself debugging core data. My experience is that depends on how many INs do you have and how many predicates you need. If you can resolve it in two or three subpredicates, it's the way to go. If you need more, usually is better to use the IN option – Christian Apr 01 '15 at 06:32

1 Answers1

0

I also ask this question on apple forums and here what i've got: probably using 'IN' is more preferable in most cases (as I expected), because request optimizer have less work to do. But to be sure I should check it with CoreData logs and instruments.

https://devforums.apple.com/message/1125377#1125377

Vladlex
  • 845
  • 8
  • 16