简体   繁体   English

为什么我要具有非标准属性?

[英]Why would I want to have a non-standard attribute?

The documentation on Core Data entities says: 有关核心数据实体的文档说:

You might implement a custom class, for example, to provide custom accessor or validation methods, to use non-standard attributes, to specify dependent keys, to calculate derived values, or to implement any other custom logic. 您可能实现一个自定义类,例如,提供自定义访问器或验证方法,使用非标准属性,指定从属键,计算派生值或实现任何其他自定义逻辑。

I stumbled over the non-standard attributes claim. 我偶然发现了非标准属性声明。 It's just a guess: If my attribute is anything other than NSString, NSNumber or NSDate I will want to have a non-standard Attribute with special setter and getter methods? 只是一个猜测:如果我的属性不是NSString,NSNumber或NSDate,我将要使用带有特殊的setter和getter方法的非标准属性吗? So, for example, if I wanted to store an image, this would be a non-standard Attribute with type NSData and a special method, say -(void)setImageWithFileURL:(NSURL*)url which then pulls the image data from the file, puts in in an NSData and assigns it to core data? 因此,例如,如果我要存储图像,这将是NSData类型的非标准Attribute和特殊方法,例如-(void)setImageWithFileURL:(NSURL*)url ,然后从文件中提取图像数据,放入NSData并将其分配给核心数据?

Or did I get that wrong? 还是我弄错了?

A non-standard attribute can be anything. 非标准属性可以是任何东西。 Some common examples are: 一些常见的示例是:

  • an image 一个图像
  • a binary key 二进制密钥
  • encrypted data 加密数据
  • audio 音讯

Just about anything that cannot be represented as a number or string falls into this category. 几乎所有不能用数字或字符串表示的东西都属于此类别。

update 更新

Transformable is not a data type of it's own. 可转换不是它自己的数据类型。 It is a way to say that a non-standard value is going to be stored here. 可以这样说,非标准值将存储在此处。 Under the covers it is binary. 在幕后它是二进制的。 The Transformable tag is a hint to Core Data to go look at the subclass's property setting. Transformable标记提示Core Data查看子类的属性设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM