不同iOS版本上的NSKeyedArchiver / NSKeyedUnarchiver兼容性 [英] NSKeyedArchiver/NSKeyedUnarchiver compatibility on different iOS versions

查看:275
本文介绍了不同iOS版本上的NSKeyedArchiver / NSKeyedUnarchiver兼容性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iOS应用中,我们通过NSKeyedArchiver / NSKeyedUnarchiver使用复杂对象的序列化来存储信息和数据。

In an iOS app, we are using serialization of complex objects through NSKeyedArchiver/NSKeyedUnarchiver to store info and data.

因此,该应用将在其中包含这样的序列化对象应用程序捆绑包,该文件将在一个特定的iOS版本(例如iOS 5.0)下创建

So the app will include such a serialized object in the app bundle, and this file will be created under one specific iOS version (let's say iOS 5.0)

由于该应用程序将在不同的iOS版本(> 5.0)上运行甚至在将来的版本中,我们都希望确保该应用程序捆绑包中包含的原始序列化对象在其他所有iOS(6.1、7.0,...)上都能完美读取。

As the app will be running on different iOS versions (> 5.0) and even in future versions to come, we want to be sure that the original serialized object included in the app bundle will be perfectly readable on every other iOS (6.1, 7.0, ...)

假设要序列化的复杂对象由所有这些iOS版本的SDK中包含其类的对象组成(为简单起见,我们假设以后在这些类上不会发生弃用),
我们可以完全确定它始终与所有iOS兼容吗?

Assuming that the complex object to serialize is composed of objects whose classes are included in the SDKs of all these iOS versions (for sake of simplicity let's assume no deprecation will occur in the future on these classes), can we be completely sure that it will always be compatible with all the iOSs?

推荐答案

通常,是的。

绝对要100%确保您您将需要使用所有自定义对象,然后您可以完全控制存档/取消存档过程。但是,只要所有类都适当地使用键控存档器的编码和解码方法,那么所有东西都将在将来兼容。

To be absolutely 100% sure you would need to use all custom objects and then you have full control over the archive / unarchive process. But, so long as all the classes are appropriately using the encode and decode methods of the keyed archiver then everything will be future compatible.

如果Apple确实决定打破这一点出于某种原因,最好的选择是捕获产生的异常并通知用户他们将需要获得对该应用程序的升级。

If Apple ever did decide to break this for some reason, you best option is to catch the resulting exception and inform the user that they will need to obtain an upgrade to the app.

您的替代方法是存储以不同的格式(例如JSON,可能是压缩格式)对数据进行初始部署,然后在应用程序启动时(如果有)使用现有版本,否则,请在应用程序启动时读取初始部署数据。

Your alternate approach is to store the initial deployment of data in a different format (like JSON, maybe compressed) then at app startup if you have an existing version, use it, if not, read in the initial deployment data.

这篇关于不同iOS版本上的NSKeyedArchiver / NSKeyedUnarchiver兼容性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆