CoreData detects deleted object after saving

if i delete the cd object and keep the mod

[self.moc deleteObject:(NSManagedObject *)someCDEntity];

[self saveMoc];

      

pointers to this cd object will become errors

when trying to access the error or ask for isDeleted I get

'CoreData could not fulfill a fault for

      

the problem is that as soon as I save the mod, isDeleted no longer works

, so how can I tell if an entity has been deleted? because just requesting isFault does not indicate that it has been deleted ... and I cannot use isDeleted

+3


source to share


2 answers


i found help on this OSX oriented thread

How do I know if the NSManagedObject file has been deleted?

- (BOOL) entityWasDeleted:(SomeEntity *)someEntity {

    return ((someEntity == nil) || ([self.moc existingObjectWithID:someEntity.objectID error:NULL] == nil));
}

      



Beware: do not use the below code as it may not always work

if (managedObject.managedObjectContext == nil) {
    // Assume that the managed object has been deleted = might not always work
}

      

+4


source


I am using prepareForDeletion method in NSManagedObject. It is called just before deletion, but as long as the object is still valid (and not erroneous). Works like a charm!



+1


source







All Articles