Master data that does not update the mapped attribute

I am using Core Data NSManagedObject (in an iOS application) with an attribute of type "transformable" to store a piece of data. Data is encoded / decoded using the NSKeyedUnarchiveFromData built-in value converter. The problem is that I was having problems setting NSManagedObject correctly after changing binary data. Let's say, for example, the code looks like this:

id temp = [myManagedObject myTransformableAttribute];

//.. do something with temp

[myManagedObject setMyTransformableAttribute:temp];

NSError *error;
if(![[myManagedObject managedObjectContext] save:&error]) {
    //present error
}

It seems to me that "reinstalling" the transformable attribute onto a managed object and saving the saved object should lead to the fact that the data will be transcoded using a NSKeyedUnarchiveFromData value transformer. But the encoder is never called, and updated data is not saved.

, . , ? - ? ...

+3
2

, NSManagedObject, ( Core Data). Apple : http://developer.apple.com/library/ios/#samplecode/Locations/Introduction/Intro.html

+ (void)initialize {
    if (self == [Event class]) {
        UIImageToDataTransformer *transformer = [[UIImageToDataTransformer alloc] init];
        [NSValueTransformer setValueTransformer:transformer forName:@"UIImageToDataTransformer"];
    }
}
+2

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


All Articles