title: Storing UIColor object in Core Data
body: <p>I want to store a UIColor object as an attribute on a Core Data entity, then retrieve it and use it in the same fashion that I do the other attributes on that entity.</p>
  
  <p>In my research, while the literature seems pretty sparse, I find <a href="https://stackoverflow.com/questions/17230720/best-way-to-save-and-retrieve-uicolors-to-core-data">this post</a> saying that the attribute should be specified as "Transformable," and that the data should be manually converted going in using <code>NSKeyedArchiver</code> and coming out using <code>NSKeyedUnarchiver</code>. </p>
  
  <p>But then, I find <a href="https://stackoverflow.com/questions/3908684/how-to-store-cgrect-and-other-things-in-core-data">a more recent post</a> saying that all that's necessary is to save the UIColor as a Transformable attribute in CD, generate a Managed Object subclass, and use just like other attributes.</p>
  
  <p>The <a href="https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/CoreData/Articles/cdNSAttributes.html#//apple_ref/doc/uid/TP40001919-SW1" rel="noreferrer">Apple docs themselves</a> go into some detail on storing and retrieving <code>NSColor</code> objects, but not (that I could find) on <code>UIColor</code>. However, it makes it sound like the archiving/unarchiving is handled automatically within CD. Maybe. I was confused by this line:</p>
  
  <p><em>If you are using the model editor in Xcode, select Transformable in the attribute’s Type popup and type the name in the Value Transformer Name text field.</em></p>
  
  <p>I assume they're talking about the name of the attribute, but am not sure, especially since it warns about potential problems arising from specifying the transformer explicitly:</p>
  
  <p><em>Important: Although the default transformer is the transformer specified by NSKeyedUnarchiveFromDataTransformerName, this transformer is actually used in reverse. If you specify the default transformer explicitly, Core Data would use it “in the wrong direction.”</em></p>
  
  <p>I've gotten to the point where I have a new transformable attribute named "color," (did not name the transformer) and have generated a new subclass file containing the new "color" property (type id). </p>
  
  <p>I'm just plain perplexed. Can someone please give me some definitive guidance on how to proceed from here?</p>
  
  <p>I'm using MagicalRecord to interface with Core Data, if that matters.</p>
  
  <p>Many thanks for helping!</p>