Is there a difference between transient properties defined in a data model or in a custom subclass of NSManagedObject?

I read that setting the value of a transient property always causes the managed object to be marked as dirty. However, I don’t understand: if I create a subclass of NSManagedObject and use some additional properties that I don’t need, this is how Core Data knows about them and how it can mark an object as dirty when I access them?

Again, they are not defined in the data model, so Core Data does not have a really good hint that they are.

Or does Core Data use some kind of introspection to parse my custom class and find out what properties I have there?

+3
source share
1 answer
NSManagedObject
/*  Distinguish between changes that should and should not dirty the object for any key unknown to Core Data.  10.5 & earlier default to NO.  10.6 and later default to YES. */
/*    Similarly, transient attributes may be individually flagged as not dirtying the object by adding +(BOOL)contextShouldIgnoreChangesFor<key> where <key> is the property name. */
+ (BOOL)contextShouldIgnoreUnmodeledPropertyChanges NS_AVAILABLE(10_6,3_0);

transition attributes can be handled by the Undo / Redo manager, and additional properties are not executed.

I discovered some strange behavior of the "dirty" data of the main data:

in iOS 5 setting the transient property in -(void)didSavemakes the context dirty, but in iOS 4.3 it doesn't.

how to make NSManagedObjectContext dirty (hasChanges = YES) manually

I don’t think master data can represent you with custom subclasses NSManagedObjects

+2
source

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


All Articles