ioscocoa-touchcore-datansvaluetransformer

Core Data not automatically calling value transformer when getting / setting attribute directly in code


If I understand correctly, the idea behind Core Data transformable attributes is:

  1. implement an NSValueTransformer subclass with returns [NSData class] in +transformedValueClass along with its implementation for transformation
  2. register the transformer in +load or +initialize
  3. set an entity's attribute as transformable
  4. set a name for your transformer (the name you used to register it) in the xcode model editor for the attribute.

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:

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 ?


Solution

  • (From the comment above:) The inverse transformer is called when you save the context, not when you set an attribute.