Core Data data model: attribute type for UIColor

后端 未结 5 745
半阙折子戏
半阙折子戏 2020-12-15 11:37

I\'m just starting out with Core Data and right now I\'m building my data model. I need a UIColor attribute for my entity, but the type dropdown for the attribute doesn\'t h

5条回答
  •  有刺的猬
    2020-12-15 12:18

    What you probably want is a transformable attribute. Give the section on "Non-standard Persistent Attributes" in the Core Data Programming Guide an other read. A transformable attribute is, underneath the covers, a binary data attribute, but Core Data will automatically use the NSValueTransformer of your specification to serialize and unserialize the logical attribute value for you. For values that are NSCoding compliant, the NSKeyedUnarchiveFromDataTransformerName (which is the default transformer) will do the trick.

    Of course, Core Data cannot index or, for an SQLite backend, query against this transformable value.

提交回复
热议问题