Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

psionides

macrumors newbie
Original poster
Jan 18, 2009
1
0
Krakow, Poland, EU
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/document...rial/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

macrumors member
Jan 31, 2005
62
7
Sweden
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.