NSKeyedArchiver/NSKeyedUnarchiver compatibility on different iOS versions

点点圈 提交于 2020-01-06 04:12:10

问题


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

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)

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, ...)

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?


回答1:


Generally, yes.

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.

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.

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.



来源:https://stackoverflow.com/questions/16538581/nskeyedarchiver-nskeyedunarchiver-compatibility-on-different-ios-versions

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