views:

156

answers:

1

Hi!

I have a NSTableView with one column bound to NSArrayController representing a collection of entities from a NSManagedObjectContext. I also have a "remove" button that is connected to NSArrayController's remove action, and it all works fine - table is showing data, when I click 'remove', the entity gets removed from the table etc.

However, this removal seems to be only happening in the object graph is never persisted to disk. Is there any flag or a way to persist such changes to object graph automatically or is the only way introducing new IBAction for the remove button and explicitely calling first remove on the controller and then save on NSManagedObjectContext?

A: 

You appear to be talking about two separate issues:

  1. "Deleting from context" versus "removing from collection" and
  2. Saving changes to a context immediately.

If your content array is bound to some other source, you can check the "Deletes objects on remove" option for the content array binding. I would expect the object be marked for deletion if the contents is merely all instances of your supplied entity (ie, the content / array binding is not established and it's just fetching all Foo instances). Saving the changes to the store ultimately deletes the objects.

To save changes immediately, you'd probably need your own separate action through which to pass your "delete this object and save" action. In that case, you can perform your remove/delete, ask the managed object context to processPendingChanges, then call the save routine.

Joshua Nozzi