Is there a way to force a managed object into the dirty state? I have a managed object that has a relationship to a parent managed object. If I change a property on the child managed object, I was curious if there is a way to put the parent managed object into a dirty state.
Share
NSPersistentDocumentfor most cases where this would be useful.UIDocument.If these aren’t possible, then you can either have the parent observe changes in its children, or have children set a changed flag on their parent. In either case, you can modify some “last changed” property to cause yourself to become dirty.
You can also create a method like
-hasChangedChildrenthat would walk the children tree and returnYESif any are dirty. This has the advantage of not actually modifying the object, so you don’t impact any Core Data optimizations. The docs do not forbid modifyinghasChangesto behave this way, but I would personally be careful doing so.But if at all possible, you should use the document classes, since this is what they’re for.
You may also be interested in Core Data Questions–Relationships, UUIDs, and Dirty States.