I create a temporary NSManagedObject and associate it with the main NSManagedObjectContext. I need to be able to consider it as a fully functioning object (execute queries for selection, etc.) inside the context and therefore cannot create it without an associated context. I include the logic for deleting a managed entity in ViewWillDisappear, provided that the new view controller was not just pushed onto the stack:
- (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; NSArray *viewControllers = self.navigationController.viewControllers; if (viewControllers.count > 1 && [viewControllers objectAtIndex:viewControllers.count-2] == self) {
This is like properly deleting a managed entity in all cases, except for application failure. I tried deleting the object in viewDidUnload, but it seems that the method is not being called when the application exits. I considered creating a second context for managed objects, but I want, if possible, to avoid the main overhead.
Thanks Graham
user487890
source share