ff10
ff10

Reputation: 3147

Does conforming to Codable give me Core Data value transformation for free like conforming to NSCoding did?

I am not very experienced with recent Core Data so please bear with me if I am missing important points here.

When conforming to NSCoding an NSObject didn't need to have it's own implementation of NSValueTransformer / ValueTransformer. You would describe it as Transformable in the Xcode model editor without defining a Value Transformer and the object would still persist as you would expect with the help of a NSValueTransfomer.

Now, Codable entered stage to replace NSCoding. The question is: does it already or will it give me the same convenience NSCoding gave me by not needing to implement a custom ValueTransformer?

Upvotes: 0

Views: 525

Answers (1)

Tom Harrington
Tom Harrington

Reputation: 70936

Core Data doesn't know anything about Codable, so conforming to Codable makes no difference to how Core Data works. It would be really nice if what you described worked, and I suggest you file an enhancement request with Apple about it. I've already done so (rdar://37708071 in case anyone from Apple reads this), and the more people who ask, the more likely they'll add this.

For now, your options are:

  • Keep using NSCoding and a transformable attribute.
  • Use Codable but then convert to/from Data yourself outside of Core Data, and use a binary attribute.

Upvotes: 1

Related Questions