Core Data数据模型:UIColor的属性类型 [英] Core Data data model: attribute type for UIColor
问题描述
我刚刚开始使用Core Data,现在我正在建立我的数据模型。我需要一个UIColor属性为我的实体,但属性的类型下拉没有这个选项。
你可能想要的是一个可变的属性。请提供有关非标准持久属性在核心数据编程指南中另一篇。一个可转换的属性在下面是一个二进制数据属性,但Core Data会自动使用你的规范的
NSValueTransformer
来序列化和反序列化逻辑属性值。对于符合 NSCoding
的值, NSKeyedUnarchiveFromDataTransformerName
(这是默认变换器)将执行。 当然,Core Data不能索引,或者对于SQLite后端,对这个可变换值进行查询。
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 have an option for this. Do I set it to Undefined or what?
Thanks
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.
这篇关于Core Data数据模型:UIColor的属性类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!