Reputation: 1701
In my NSManagedObject subclass I have an NSString ivar that splits up into an NSSet of entities. I'd like to be able to set the string and during a call to save, do the split, however, only setting the string will not trigger a dirty flag or a need to save.
Upvotes: 4
Views: 1454
Reputation: 12504
You can implement the + (BOOL)contextShouldIgnoreUnmodeledPropertyChanges
on you NSManagedObject
subclass and return NO
rather than the default (YES
).
This should then cause the NSManagedObjectContext
to be notified of changes properties even if they aren't represented by actual columns in the database.
Upvotes: 1
Reputation: 80273
I assume you mean "attribute" instead of "ivar". Your scheme of having a string being split into a set and then saving the set is perhaps debatable, but I guess that is not the issue here.
Why do you need to have the Managed Object marked as "dirty"? This is really not necessary. Just save it, dirty or not!
I do not know how you check the "dirtiness" of your managed object, but I assume you want this to trigger a save at a certain point. At that point you might just as well as check your own BOOL
"dirtyFlag" which you can set as appropriate and keep available for checking.
It is always better to make these kinds of things explicit. Your code will become more readable and transparent.
Upvotes: 0