2
從我的iPhone應用程序,我通過將數據發送到我的收藏的應用程序:與iPhone應用程序Watchkit共享數據,NSInvalidUnarchiveOperationException
func application(application: UIApplication!, handleWatchKitExtensionRequest userInfo: [NSObject : AnyObject]!, reply: (([NSObject : AnyObject]!) -> Void)!) {
if let data = NSKeyedArchiver.archivedDataWithRootObject(Country()) {
reply(["data": data])
}
}
在我的收藏的應用程序,我試圖讀取數據:
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)'
[WatchKit和NSUserDefaults的問題NSKeyedUnarchiver]的可能重複(http://stackoverflow.com/questions/28383549/watchkit-nsuserdefaults-and-nskeyedunarchiver-issue) – Jano 2015-02-11 21:00:30