Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is an NSArrayController "losing" its sort after an object is inserted?
    primarykey
    data
    text
    <p>I have an NSArrayController bound to a property of an NSManagedObject subclass. The subclass is automatically generated by mogenerator (which creates a set property for the relationship).</p> <p>The NSArrayController is bound to network.posts where 'posts' is a 1-M relationship. Note I am binding to 'posts' rather than the 'postsSet' mutableSet accessor generated by mogenerator.</p> <p>The set represents a relationship with another entity. The array controller has a sort descriptor set and, when the window it is associated with opens, data is displayed in the correct sort order.</p> <p>Then I add a new object by instantiating an entity and then adding it to the relationship.</p> <p>The NSArrayController is correctly observing this change and the new object appears in <em>arrangedObjects</em> however, after the insert the sort order of arrangedObjects is lost and the records appear in a different order.</p> <p>I have verified that the sort descriptor is still set correctly. The NSArrayController has autoRearrangeContent=YES. I've even tried manually calling -rearrangeObjects after the insert but the sort order remains wrong.</p> <p>If I close the window and re-open the newly instantiated NSArrayController has the data with the correct sort order again. Until I do another insert.</p> <p>My experience has been that NSArrayController has automatically kept the correct sort order when objects are added/removed but maybe that was a lucky coincidence?</p> <p>I can't find any description of the correct behaviour in the Apple document so I've no idea what to expect, what might be going wrong (if anything), or - in either case - what I should do about it.</p> <p>1) Given a sortDescriptor should NSArrayController be keeping arrangedObjects sorted after objects are inserted/removed from the underlying collection?</p> <p>2) If so, what might prevent this from happening?</p> <p>3) And, if not, what is the correct way to keep arrangedObjects sorted?</p> <p>I'd be grateful for any help. It's not easy to provide useful source code in this situation since, in principle, there isn't any. But I'm happy to clarify and answer any follow-up questions.</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