I have an NSArrayController associated with a property of a subclass of NSManagedObject. A subclass is automatically generated by the generator (which creates the set property for the relation).
NSArrayController is tied to network.posts, where "messages" are 1-M relationships. Note. I am attached to the "messages", and not to the "accessSet" mutableSet accessory generated using mogenerator.
A set is a relationship with another object. The array controller has a set of sort descriptors, and when a window is associated with opening, the data is displayed in the correct sort order.
Then I add a new object, instantiating the object and adding it to the relation.
NSArrayController respects this change correctly, and the new object appears in the ordered objects, but after insertion, the sort order of the ordered objects is lost and the records appear in a different order.
I checked that the sort descriptor is still set correctly. NSArrayController has autoRearrangeContent = YES. I even tried to manually call -rearrangeObjects after insertion, but the sort order remains wrong.
If I close the window and open the newly created NSArrayController again, you will have data with the correct sort order. Until I do one more insert.
My experience is that NSArrayController automatically maintained the correct sort order when objects were added / removed, but maybe this was a lucky coincidence?
I can’t find any description of the correct behavior in the Apple document, so I don’t know what to expect, what could be wrong (if you like) or - in any case - what should I do with it.
1) Given sortDescriptor, should NSArrayController save ordered objects sorted after objects are inserted / removed from the base collection?
2) If so, what could prevent this?
3) And if not, what is the way to save ordered ordered objects?
I would be grateful for any help. In this situation, it is not easy to provide useful source code, since in principle it is not. But I am happy to clarify and answer any subsequent questions.