Is there a way to mark NSManagedObject as dirty?

In my subclass of NSManagedObject, I have an ivar nSString that breaks down into NSSet entities. I would like to be able to set the line and during the call to save, do the splitting, however, just setting the line will not cause a dirty flag or the need to save.

+4
source share
2 answers

I assume that you mean "attribute" instead of "ivar". Your scheme to have a string breaks into a set and then save the set is arguably debatable, but I assume this is not a problem.

Why do you need a managed entity to be marked as dirty? It really is not necessary. Just keep it dirty or not!

I do not know how you check the “dirtyness” of your managed entity, but I assume that you want this to cause persistence at some point. At this point, you can check your own BOOL "dirtyFlag" in the same way, which you can set accordingly and save for verification.

It is always better to make such things clear. Your code will become more readable and transparent.

0
source

You can implement + (BOOL)contextShouldIgnoreUnmodeledPropertyChanges in a subclass of NSManagedObject and return NO , not the default ( YES ).

This should then cause NSManagedObjectContext to receive notification of property changes, even if they are not represented by the actual columns in the database.

0
source

Source: https://habr.com/ru/post/1398144/


All Articles