Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>To clarify things: all of the methods in the interface perform set operations because they all refer to a to-many relationship. The difference between addEmployeeObject: and addEmployees: is that the former adds a single object while the latter adds many of them at the same time. The set operation performed is in this case set union, while for removeEmployeeObject: and removeEmployees it is set difference of course. </p> <p>Why you should not think of this in terms of appending to the previous collection of elements already stored? Because Core Data represents a to-many relationship using a NSSet (a collection of distinct elements), not a NSCountedSet (a set that can contain duplicate elements, also known as a bag). And because a set is an unordered collection therefore "appending" does not make sense (as it does instead for an array or list). Core Data (correctly) does not allow repeated elements stored in the same to-many relationship, therefore the framework uses a NSSet, which enforces distinct elements (while NSCountedSet allows duplicate elements).</p> <p>Finally, when you use the setEmployees: method, you are releasing the current set of employees stored in the to-many relationships and retaining the set you passed as an argument to the setEmployees: method. Therefore you are changing one-shot the elements stored in the relationship. It is perfectly equivalent to removing first all of the elements stored in the relationship, then adding the new ones (assuming of course they are all distinct).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload