3

if i delete an cd entity and than save the mod

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

[self saveMoc];

the pointers to this cd entity will become faults

by trying accessing the fault or ask for isDeleted, i get a

'CoreData could not fulfill a fault for

the problem is, as soon as i save the mod, the isDeleted doesn't work any more

so how can i detect if an entity is removed? because just asking for isFault, doesn't indicate that it was deleted... and i cannot use isDeleted

Peter Lapisu
  • 19,915
  • 16
  • 123
  • 179

2 Answers2

4

i found help in this OSX oriented thread

How can I tell whether an `NSManagedObject` has been deleted?

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

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

Beware : don't use the code bellow, as it might not always work

if (managedObject.managedObjectContext == nil) {
    // Assume that the managed object has been deleted = might not always work
}
Community
  • 1
  • 1
Peter Lapisu
  • 19,915
  • 16
  • 123
  • 179
  • Thanks for mentioning the beware, as I was just about to implement it that way. It makes sense that the first snippet is more reliable. – DonnaLea May 07 '14 at 00:57
1

I use the prepareForDeletion method in NSManagedObject. It is called just before the deletion but while the object is still valid ( and not faulted ). Works like a charm!

moritz
  • 2,448
  • 1
  • 20
  • 25