Core Data - NSPersistentDocument tutorial

Discussion in 'Mac Programming' started by psionides, Jan 18, 2009.

  1. psionides macrumors newbie

    Jan 18, 2009
    Krakow, Poland, EU

    I'm going through Apple's NSPersistentDocument tutorial, and I have one problem... On the page "Cut" in the tutorial (, there is code that you need to add to allow deleting Employees from Department (both from a relation between entities and from the managed object context). It says that you just need to call deleteObject: on the context and that's all.

    The thing is, this doesn't work for me. When I press Cmd+X, an employee isn't deleted from the table. I've found some other example somewhere on the web, which also added [context processPendingChanges] after the delete, and when I added that, it started working. But why didn't it work without that, if the tutorial doesn't mention that you need to call that method? Is the tutorial wrong, or am I doing something wrong? Can anyone please clarify this to me?

    Best regards,
  2. Bakerman macrumors member

    Jan 31, 2005
    The documentation for -[NSManagedObjectContext deleteObject:] states that the the object will be removed when changes are committed. If you need it removed from the table, call -[NSArrayController removeObject] (assuming that you have the table content bound to an NSArrayController) instead. Depending on how you get the content into the NSArrayController in the first place, this may or may not mark the object for deletion in the managed object context, too.

Share This Page