Note that there are some explanatory texts on larger screens.

plurals
  1. POManaging an Ordered Core Data Relationship Using NSArrayController
    text
    copied!<blockquote> <p>All those “NSOrderedSet was added later and thus doesn’t have to play nice with other components” bugs drive me crazy…</p> <p><em>(<a href="https://twitter.com/kubanekl/status/413447039855640576" rel="nofollow noreferrer">https://twitter.com/kubanekl/status/413447039855640576</a>)</em></p> </blockquote> <p>I have two managed objects and an ordered 1:N relationship between them, which is backed by an instance (or more precise a subclass) of <code>NSOrderedSet</code>. I want to manage this relationship using a <code>NSArrayController</code> in order to profit from features it offers (selection management, binding of the content, bindings to views like <code>NSTableView</code>).</p> <p>Since <code>NSOrderedSet</code> is not a subclass of <code>NSSet</code>, the <code>contentSet</code> binding of <code>NSArrayController</code> doesn't work with that relationship. I found <a href="https://stackoverflow.com/questions/15078679/binding-an-ordered-relationship-with-an-nsarraycontroller">following thread</a> and tried to implement the suggestions mentioned there.</p> <p>The first suggestion is to use the <code>contentArray</code> binding and a value transformer for transforming the ordered set to an array on the fly. The problem with this solution is the <strong>reassigning</strong> of the content each time a change is made, which is not what I want.</p> <p>The second suggestion provided in the mentioned thread is to use the <code>contentArray</code> binding and apply the <code>@array</code> operator to the model key path. I've tried that, but the underlying relationship was <strong>not touched at all</strong> when adding/removing objects through the <code>NSArrayController</code>.</p> <p>Another option I found is using sort descriptors with the <code>contentSet</code> binding. This would require making the relation unordered in order to make the <code>contentSet</code> binding work and introducing a <strong>new attribute</strong> used especially for managing the order. This would furthermore require a <strong>custom ordering mechanism</strong> to implement and it would <strong>mess up the model</strong>. Honestly said, I would like to avoid this solution.</p> <p>My question is pretty clear: Is there any way to manage an ordered Core Data relationship using <code>NSArrayController</code>? If so, which is the best way causing as little pain as possible?</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