Where to implement NSValueTransformer for Core Data in Swift

别说谁变了你拦得住时间么 提交于 2019-12-02 07:44:36

The "where" is just anywhere in your project. Anywhere that ensures that your NSValueTransformer subclass will exist at run time. Implement the NSValueTransformer subclass, and enter the class name in the Core Data model as the value transformer.

However there is a default transformer. Any class that adopts the NSCoding protocol can be automatically transformed by Core Data. In that case you mark the attribute as transformable but don't include a class name. This includes NSURL, so you don't need to transform that or convert it to a string.

For your NSDocument subclass then, you have the option of either implementing NSCoding in the class or of implementing an NSValueTransformer subclass for the document type.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!