Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to efficiently get all instances from deeper level in Cocoa model?
    primarykey
    data
    text
    <p>In my Cocoa Mac app I have an instance <code>A</code> which contains an unordered set of instances <code>B</code> which in turn has an ordered set of instances <code>C</code>. An instance of <code>C</code> can only be in one instance <code>B</code> and <code>B</code> only in one <code>A</code>.  </p> <p>I would like to have an unordered set of all instances <code>C</code> available on instance <code>A</code>. I could enumerate over all instances <code>B</code> each time, but that seems expensive for something I need to do often. However, I am a bit worried that keeping track of instances <code>C</code> in <code>A</code> could become cumbersome and be the cause of  inconsistencies, for example if an instance <code>C</code> gets removed from <code>B</code> but not from <code>A</code>. </p> <p><em>Solution 1</em> – Use a <code>NSMutableSet</code> in <code>A</code> and add or remove <code>C</code> instances whenever I do the same operation in <code>B</code>. </p> <p><em>Solution 2</em> – Use a weak referenced <code>NSHashTable</code> in <code>A</code>. When deleting a <code>C</code> from <code>B</code> it should disappear for <code>A</code> as well. </p> <p><em>Solution 3</em> – Use key value observing in <code>A</code> to keep track of changes in <code>B</code>, and update a <code>NSMutableSet</code> in <code>A</code> accordingly. </p> <p><em>Solution 4</em> – Simply iterate over all instances <code>B</code> to create the set whenever I need it.  </p> <p>Which way is best? Are there any other approaches that I missed? </p> <p>NB I don't and won't use CoreData for this app. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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