Does calling a "count" in relation to many CoreData-related relationships with all objects in the collection?

Say that I have an “Employee” entity with “multi-relationship departments” with another “Department” unit. If I have an instance of an Employee object and the department collection is currently an error, what is the most efficient memory method for counting departments?

Two obvious options:

1) call [myEmployee.departments count];

2) Building a fetchRequest to return only Department objects whose correspondence "employee" points to my employee object and then calls countForFetchRequest:

Besides using memory, will one of these methods be carelessly faster than the other?

+5
source share
2 answers

No relationship received unless you have a KeyPathsForPrefetching relationship.

However, my best advice for you is to always carry out your decision in the most direct way, and THEN will solve performance problems later. People are notoriously poorly predicting performance problems.

One tool that is very easy to use is the tools that are included with Xcode.

You can easily run the test using both approaches, and actually compare the numbers, rather than just stick to the opinion of some stranger on SO.

0
source

First: When the connection is called an object, the object is loaded as an “error”, so the performance is so good.

Second: if you use the countForFetchRequest method, the request will look like this:

NSFetchRequest *f = Departament.fetchRequest;

f.predicate = [NSPredicate predicateWithFormat:@"ANY employees = %@", employe.objectID];

CoreData , . .

  • .
  • , , . countForFetchRequest, - .
0

All Articles