Storing UIColor object in Core Data

Your attribute should be of the type Transformable. The default value transformer (NSKeyedUnarchiveFromDataTransformerName) can transform any object that conforms to NSCoding.

  1. Mark the attribute as type “Tranformable”.
  2. Optional: Set the Value Transformer Name to “NSKeyedUnarchiveFromDataTransformerName”. If you do not, it will default to this anyway.

Like so

You do not have to do anything else. Keep in mind you will not be able to match transformable attribute with a predicate or sort by them. They are pretty much just storage – the value transformer transforms the object value into NSData, which is what gets persisted in the store. When the attribute fault fires Core Data uses the transformer in the other direction to go from NSData to your object type.

Leave a Comment