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

查看:166
本文介绍了Core Data数据模型: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屋!

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