• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: What exactly happens when I use Core Data's 'Remove' button?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What exactly happens when I use Core Data's 'Remove' button?


  • Subject: Re: What exactly happens when I use Core Data's 'Remove' button?
  • From: Chris Hanson <email@hidden>
  • Date: Fri, 11 Aug 2006 11:51:34 -0700

On Aug 11, 2006, at 6:32 AM, Arthur C. wrote:

I have a Core Data application where I can add and remove objects from a table. When I use the 'add' button, a method 'awakeFromInsert' is called, which I can use to set up data management such as key-value observing.

Is there a similar method that gets called when the 'remove' button is used? I found that neither the 'dealloc' nor the 'didTurnIntoFault' method gets called. The object-to-be-removed should at least be unregistered as KVO observer. Failing to do this leads to strange behaviour: the removed object reappears in the table view (!) when changing a key this object was observing.
So another question is why the object is not actually deleted (I would expect it to be dealloc-ed).

To expand a little on what others have said, it's not really correct to talk about "Core Data's 'Remove' button". Core Data is a model- level technology; your human interface (view) is connected to the model via a controller, in this case probably the array controller you generated by option-dragging the representation of an entity from an Xcode data model to a window in Interface Builder.


When you click the "Remove" button, the button sends -remove: to the associated array controller. The array controller will then perform the correct operation on its selection (if any). What the "correct operation" is depends on whether the array controller is managing a relationship or all instances of an entity.

If an array controller is managing a relationship — in other words, if its contentSet binding is configured — then it will simply remove its selected objects from that relationship. You can override this behavior by setting the Deletes Objects on Remove build setting, which will cause the array controller to first remove its selected objects from the relationship and then ask its managed object context to delete them.

If an array controller is managing all instances of an entity, when it receives -remove: it will ask its managed object context to delete the selected objects. And when a managed object context is asked to delete an object, that doesn't actually dispose of the object immediately. It marks the object as deleted and will actually remove the object when the context is saved.

You can think of this as sort of like a database transaction: If you have a database and start a transaction, then ask the database to delete some rows, they aren't actually deleted in a way that's visible to any other users until the transaction is committed. If the transaction is rolled back instead of committed, the deletion is actually undone.

  -- Chris


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >What exactly happens when I use Core Data's 'Remove' button? (From: "Arthur C." <email@hidden>)

  • Prev by Date: Re: Two views
  • Next by Date: From Big Endian to Little Endian
  • Previous by thread: Re: What exactly happens when I use Core Data's 'Remove' button?
  • Next by thread: NSArrayController arrangedObjects not showing any result
  • Index(es):
    • Date
    • Thread