PDA

View Full Version : Core Data - NSPersistentDocument tutorial




psionides
Jan 18, 2009, 12:59 PM
Hi,

I'm going through Apple's NSPersistentDocument tutorial, and I have one problem... On the page "Cut" in the tutorial (http://developer.apple.com/documentation/Cocoa/Conceptual/NSPersistentDocumentTutorial/05_CopyAndPaste/chapter_6_section_5.html), 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,
Jakub



Bakerman
Jan 18, 2009, 02:25 PM
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.