简体   繁体   English

如何在核心数据中正确保存可转换对象?

[英]How can I correctly save transformable objects in core data?

I'm building an app that uses core data.我正在构建一个使用核心数据的应用程序。 There I save arrays of strings, UIColor and UIImage.在那里我保存了字符串、UIColor 和 UIImage 的 arrays。 All with transformable types.都具有可转换的类型。
However I noticed I get the following error:但是我注意到我收到以下错误:

'NSKeyedUnarchiveFromData' should not be used to for un-archiving and will be removed in a future release 'NSKeyedUnarchiveFromData' 不应用于取消归档,并将在未来版本中删除

I found and implemented a few demonstrations like this one and I was wondering if these were the best solutions to get rid of the error.我发现并实施了一些类似这样的演示,我想知道这些是否是摆脱错误的最佳解决方案。
Everything seems to work pretty good but, for me, it did using transformables as well until I saw that error.一切似乎都很好,但对我来说,它也使用了可变形对象,直到我看到那个错误。
So I'm looking for the correct way to save these transformable types in core data.所以我正在寻找将这些可转换类型保存在核心数据中的正确方法。

The linked article covers the topic very well.链接的文章很好地涵盖了该主题。 The log in the console you are getting is not an error, but a warning.您得到的控制台日志不是错误,而是警告。 We have encountered the same issue and every solution points to using NSSecureUnarchiveFromData which in fact seems to be a correct one for the problem.我们遇到了同样的问题,每个解决方案都指向使用NSSecureUnarchiveFromData实际上似乎是解决问题的正确方法。 We have been using it in production for quite a while now and everything works as expected and the warning is gone.我们已经在生产中使用它很长一段时间了,一切都按预期工作,警告消失了。 And you should be treating it for what it is, a warning.你应该按照它的本来面目对待它,一个警告。 It it does resurface at any time for some specific type that you are trying to store in your CoreData, you could try implementing a custom transformer just like its shown in the article.对于您尝试存储在 CoreData 中的某些特定类型,它确实会随时重新出现,您可以尝试实现一个自定义转换器,就像它在文章中显示的那样。 Good luck!祝你好运!

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

相关问题 如何使用Swift使用Core Data更新/保存和保留非标准(可转换)属性? - How can I get non-standard (transformable) attributes to update/save and persist using Core Data with Swift? 我可以在iPhone上的Core Data中使用Transformable属性类型做什么? - What can I do with an Transformable attribute type in Core Data on the iPhone? 具有自定义对象的核心数据中的可转换集合 - Transformable Collection in Core Data with custom Objects 如何从iOS的核心数据可转换字段中获取RTF内容? - How can I get RTF content out of a core data transformable field on iOS? 如何更新核心数据中的可变形属性 - How to update transformable attribute in core data 如何将NSDictionary存储为核心数据中的可转换属性 - how to store NSDictionary as transformable properties in core data 核心数据可转换属性 - Core Data Transformable Attribute iOS核心数据可转换 - iOS Core Data transformable 如何最好地将要用作UIImage的图像存储在Core Data存储中? 变形? 二进制数据? - How would I be best off storing images to be used as a UIImage in a Core Data store? Transformable? Binary data? 核心数据保存问题:无法更新可转换属性(NSArray) - Core Data saving problem: can't update transformable attribute (NSArray)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM