【发布时间】:2016-01-18 14:16:03
【问题描述】:
- 我的 IOS-App 有 2 个目标:MYAPPTARGET_1 和 MYAPPTARGET_2
- MYAPPTARGET_1 正在使用 NSKeyedArchiver 将 Stream 写入 BLOB
- MYAPPTARGET_2 正在使用 NSKeyedUnarchiver 从 BLOB 中读取 Stream
从我的 MYAPPTAARGET_2 中的 BLOB 中取消归档流时,我收到错误消息: 016-01-18 15:01:38.541 WorldHistoryAtlasTest[598:9405] * 由于未捕获的异常“NSInvalidUnarchiveOperationException”而终止应用程序, 原因:'* -[NSKeyedUnarchiver decodeObjectForKey:]:无法解码类的对象 (MYAPPTARGET_1.MapTheme) 用于键(根对象);
所以它似乎显然是用 MYAPPTARGET_1 前缀编码的,并且无法从 MYAPPTARGET_2 读取。
所以我在另一个 STACKOVERFLOW 答案中得到了克服这个问题的提示,以使用委托解档器覆盖类名。但我无法实现这一点:
func unarchiver(unarchiver: NSKeyedUnarchiver, cannotDecodeObjectOfClassName name: String, originalClasses classNames: [String]) -> AnyClass? {
print("ClassName is " + name);
return nil; // WHAT TO DO , TO OVERWRITE THE CLASS NAME.
}
var mykeyedunarchiver:NSKeyedUnarchiver=NSKeyedUnarchiver(forReadingWithData: data!);
mykeyedunarchiver.delegate = self;
let temp=mykeyedunarchiver.decodeObjectForKey("rootobject")
我有一个目标名称为 MYAPPTARGET_1 的应用,我使用 NSKeyedArchiver 功能将一些数据存储为 blob。
稍后,我使用名为 MYAPPTARGET_2 的第二个 Apps-Target 尝试再次读取数据。从存储在 DB 中的 BLOB 加载。
如果有人能给我一个实用的提示,我会很高兴的。
【问题讨论】:
标签: swift delegates nskeyedarchiver nskeyedunarchiver