核心数据数据模型:UIColor 的属性类型 [英] Core Data data model: attribute type for UIColor

查看:32
本文介绍了核心数据数据模型:UIColor 的属性类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用 Core Data,现在我正在构建我的数据模型.我的实体需要一个 UIColor 属性,但该属性的类型下拉列表没有此选项.我是否将其设置为未定义或什么?

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?

谢谢

推荐答案

您可能想要的是一个可转换的属性.给出关于Non-standard Persistent Attributes" in the Core Data Programming Guide 另一个阅读.一个可转换的属性实际上是一个二进制数据属性,但 Core Data 会自动使用您规范的 NSValueTransformer 为您序列化和反序列化逻辑属性值.对于符合 NSCoding 的值,NSKeyedUnarchiveFromDataTransformerName(这是默认转换器)将起作用.

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.

当然,Core Data 不能索引,或者对于 SQLite 后端,不能查询这个可转换的值.

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

这篇关于核心数据数据模型:UIColor 的属性类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆