Re: NSArrayController in entity mode and permutations (CoreData question)
Re: NSArrayController in entity mode and permutations (CoreData question)
- Subject: Re: NSArrayController in entity mode and permutations (CoreData question)
- From: Quincey Morris <email@hidden>
- Date: Mon, 12 Apr 2010 11:07:08 -0700
On Apr 12, 2010, at 10:14, vincent wrote:
> I did try to insert the moved object in another array *before* deleting and reinserting it (and then deleting it from the other array). AFAIK, inserting an object in a NSArray retains it. TO no avail.
Ah, ok, sorry -- trying the easiest answer first was worth a try. :)
> I am trying to solve this issue using proxy objects.
So we move on to possible answer B. From the description of -[NSArrayController removeObject:]
"If you are using Core Data, the exact semantics of this method differ depending on the settings for the array controller. If the receiver’s content is fetched automatically, removed objects are marked for deletion by the managed object context (and hence removal from the object graph). If, however, the receiver’s contentSet is bound to a relationship, removeObject: by default only removes the object from the relationship (not from the object graph). You can, though, set the “Deletes Object on Remove” option for the contentSet binding, in which case objects are marked for deletion as well as being removed from the relationship."
I think the real problem is that you're not seeing the implication of NSArrayController's being a proxy object -- you cannot "remove" objects from *just* the array controller (and re-insert them later), because the array controller doesn't contain any objects -- it's merely a proxy for the actual container, and removing objects from the actual container has side-effects in the Core Data case (at least the way NSArrayController does it, some of the time).
Answer C:
Also, because the content set has no order, the order of the objects in the array controller's arrangedObjects (if you could manipulate it the way you want) would have no way of persisting, and you'd have to be certain that nothing ever caused the controller's arrangeObjects method to be called, directly or indirectly.
Surely it would be more robust to make the order explicit in your data model (with a transient property if the order really is transient) and let the array controller keep the displayed content sorted according to that order?
Answer D:
You seem to be getting awfully close to trying to program your data model by "remote control" via NSArrayController -- which may seem attractive because they superficially seem a bit easier to program. (You want an ordering on your otherwise-unordered Core Data objects, and you're taking a short cut by implementing the ordering via NSArrayController, instead of enhancing your data model to support the desired order.) This isn't really the purpose of array controllers, and torturing them in this way often (as we see on this list) ends up torturing the developer even more.
Again, I think you'd be much better off finding a solution properly within your data model.
Of course, answer D is largely a matter of opinion -- and answer C to some degree. FWIW.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden