문제

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

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.

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?

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

도움이 되었습니까?

해결책

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.

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top