简体   繁体   English

使用 NSKeyedUnarchiver 解码 NSArchiver

[英]Decoding NSArchiver with NSKeyedUnarchiver

I have some old archives that are basically stored preferences created with NSArchiver.我有一些旧档案,它们基本上是使用 NSArchiver 创建的存储首选项。 I want to be able to decode them with NSKeyedUnarchiver since the NSArchiver/NSUnarchiver are deprecated in favor of their keyed counterparts.我希望能够使用 NSKeyedUnarchiver 对它们进行解码,因为不推荐使用 NSArchiver/NSUnarchiver 以支持它们的键控对应物。

Is there any way to make this work?有什么办法可以使这项工作?

You cannot decode an NSArchiver archive with NSKeyedUnarchiver.您无法使用 NSKeyedUnarchiver 解码 NSArchiver 存档。 The NSArchiver format is deprecated, not just the classes. NSArchiver格式已被弃用,而不仅仅是类。 If you have data in the old format, you may have to use a deprecated class to decode it.如果您有旧格式的数据,您可能必须使用已弃用的 class 对其进行解码。 The point is that you would then re-encode the data using NSKeyedArchiver (or one of the other options like Codable in Swift) and store it in a modern format.关键是您将使用 NSKeyedArchiver(或其他选项之一,如 Swift 中的 Codable)重新编码数据并将其存储为现代格式。

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

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