If I understand correctly, the idea behind Core Data transformable attributes is:
NSValueTransformer
subclass with returns [NSData
class]
in +transformedValueClass
along with its implementation
for transformation+load
or +initialize
At this point, I'd expect that accessing or setting the attribute in a managedObject of the appropriate entity type would trigger the value transformer. However, I'm testing this in an app that uses AFIncrementalStore
and I get the following behavior:
+load
or +initialize
doesn't
seem necessary; Core Data finds it anyway (though read ahead).AFIncrementalStore
do trigger the
transformer. For example, I get JSON back from a fetch request and
when mapping the response dictionary to the managedObject, the
transformer is triggered and coverts the appropriate dictionary key
to NSData
in the object.myManagedObject.myAttribute = @"hello"
does not trigger the
conversion from NSString
to NSData
and neither does NSString
*myString = myManagedObject.myAttribute
trigger the conversion from NSData
to NSString
.So what am I missing? I thought the idea was that CoreData would automatically call the transformer. Am I wrong?
According to this question: Why is my transformable Core Data attribute not using my custom NSValueTransformer? this seems to be a bug in the Apple frameworks. But what throws me off is that via AFIncrementalStore the value transformer does get called. Maybe the key is that by setting just an attribute via code I am not really triggering AFIncrementalStore and so the change is merely in-memory ?
(From the comment above:) The inverse transformer is called when you save the context, not when you set an attribute.