Question

I'm trying to remove a managed object context, but instead of removing the object itself it sets all instant variables to null. Am I doing anything wrong while deleting an instant of NSManagedObjectContext?

@implementation MyManagedObject

- (BOOL)submitToServer
{
     if (/*submitted successfully*/)
     {
          return YES;
     }
     else
     {
          [self.managedObjectContext deleteObject:self];
          return NO;
     }
}

@end
Was it helpful?

Solution

You must call [self.managedObjectContext save:nil] after deleteObject for the delete to be committed to the persistent store. Read more about deleting a managed object.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top