I have two classes in my underlying data model: Sample
and Photo
, with a 1: N ratio. I use the only NSManagedObjectContext
in my application, which is used as a notepad for managed objects. Therefore, I always insert a newly created object into the context. If users decide to abandon their changes, I just roll back from the context. Otherwise, the context is preserved.
Error
CoreData: error: Mutation of the managed object 0x1704253a0 (0x1702a1560) after its removal from the context.
prints to the console after the Photo
object is removed from the context. Deletion occurs before the context is saved, so Photo
objectID
is temporary. Here is a quick code:
function addPhoto(to sample: Sample) -> Photo { let photo = Photo(context: managedObjectContext) sample.addToPhotos(photo) photo.sample = sample return photo } function remove(photo: Photo) { photo.sample.removeFromPhotos(photo) photo.sample = nil managedObjectContext.delete(photo) }
The strange thing is that there is no error or exception, and my code completes to the end. However, the error message is displayed on the console.
I believe this happens because the context invalidates all Photo
properties before deleting it. I know that the properties are revoked because I added observers to them.
How to prevent this error from appearing in the console?
Thanks.
source share