我可以在iPhone上的Core Data中使用Transformable属性类型做什么? [英] What can I do with an Transformable attribute type in Core Data on the iPhone?

查看:168
本文介绍了我可以在iPhone上的Core Data中使用Transformable属性类型做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

属性有Transformable数据类型。它有什么好处?有很好的例子吗?

There's this Transformable data type for attributes. What is it good for? Are there good examples?

我想玩这个。所以后搜索一段时间我遇到这个:NSValueTransformer。似乎是我需要的东西。

I'd like to play around with this. So after searching a while I came across this: NSValueTransformer. Seems to be something I need for this.

那么我该如何开始呢?例如,如果我想存储一个UIColor对象,我会为这个变换器吗?

So how would I get started with this? For example, if I wanted to store an UIColor object, would I make an transformer for that?

这个东西到底是什么东西转换? NSData?

What exactly is this thing transforming to or from? An NSData? And must the object which I pass to the transformer follow any protocol?

推荐答案

可变属性对于在Core内存储非标准对象类型非常有用数据。例如,我在此答案,允许您将UIImages存储为Core Data中的属性。将图像数据转换为包含图像的PNG表示形式的NSData实例并从中转换。

Transformable attributes are useful for storing nonstandard object types within Core Data. For example, I provide code in this answer that lets you store UIImages as an attribute within Core Data. The image data is converted to and from an NSData instance that contains the image's PNG representation. This is all handled transparently for you by a custom NSValueTransformer.

您还可以在Core Data模型中加密个别属性,如在这里说明。使用transformable属性,这使得这个无关紧要的代码。

You may also wish to encrypt individual attributes within your Core Data model, as I describe here. Using a transformable attribute for this makes this trivial to code.

这篇关于我可以在iPhone上的Core Data中使用Transformable属性类型做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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