【发布时间】:2015-02-07 23:42:33
【问题描述】:
从我的 iPhone 应用程序中,我通过以下方式将数据发送到我的 Watch 应用程序:
func application(application: UIApplication!, handleWatchKitExtensionRequest userInfo: [NSObject : AnyObject]!, reply: (([NSObject : AnyObject]!) -> Void)!) {
if let data = NSKeyedArchiver.archivedDataWithRootObject(Country()) {
reply(["data": data])
}
}
在我的 Watch 应用中,我正在尝试读取数据:
WKInterfaceController.openParentApplication(input, reply: { (replyValues, error) -> Void in
if error == nil {
if let data = replyValues["data"] as? NSData {
if let temp = NSKeyedUnarchiver.unarchiveObjectWithData(data) as? Country {
println("done")
}
}
}
})
抛出以下错误:
Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: '*** -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (Country)'
【问题讨论】: