最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[已解决]NSInvalidUnarchiveOperationException NSKeyedUnarchiver decodeObjectForKey  cannot decode object of class for key  NS.objects

Swift crifan 4983浏览 0评论

代码:

    func restoreData(){
        dispatchBackground_async({
            calcTimeStart("RestoreConversationItemList")
            if let savedFilePath = findSavedFilePath(ArchiveConversationDir, savedFilename: "conversationItemList") {
                if let conversationItemListObj = NSKeyedUnarchiver.unarchiveObjectWithFile(savedFilePath){
                    let restoreConversationItemList = conversationItemListObj as! [ConversationItem]
                    self.isRestored = true
                    self.conversationItemList = restoreConversationItemList
                    self.tableView.reloadData()
                    gLog.info("restored \(self.conversationItemList.count) conversations from \(savedFilePath)")
                } else {
                    gLog.warning("restore conversationItemList fail")
                }
            } else {
                gLog.info("not found saved conversation item list")
            }
            calcTimeEnd("RestoreConversationItemList")
        })
    }

中的:

                if let conversationItemListObj = NSKeyedUnarchiver.unarchiveObjectWithFile(savedFilePath){

出错:

2016-04-02 11:32:49.935 JianDao[34302:1911704] *** Terminating app due to uncaught exception ‘NSInvalidUnarchiveOperationException’, reason: ‘*** -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (简道.ConversationItem) for key (NS.objects); the class may be defined in source code or a library that is not linked’
*** First throw call stack:
(
    0   CoreFoundation                      0x02d40494 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x0444ee02 objc_exception_throw + 50
    2   Foundation                          0x020425d6 -[NSCoder(Except

 NSKeyedUnarchiver decodeObjectForKey  cannot decode object of class for key  NS.objects the class may be defined in source code or a library that is not linked

Decode object in WatchKit Extension | Apple Developer Forums

objective c – NSKeyedUnarchiver cannot decode object of class NSKnownKeysDictionary1 – Stack Overflow

objective c – Passing NSArray of custom objects as NSData via WatchConnectivity’s sendMessageData – Stack Overflow

ios – NSKeyedUnarchiver error after renaming Xcode project – Stack Overflow

ios – How can I decode an object when original class is not available? – Stack Overflow

基本上确定是之前的:

[已解决]swift的app的中文名内部调试输出时显示乱码

把app的名字,从中文 简道 改为英文 JianDao 而导致找不到之前的

简道.ConversationItem

了,

现在去,删除之前的旧程序,重现安装,应该是可以解决的

但是,还是为了保险起见

想要去给这个函数,加上异常处理,至少当decode出错时,不至于导致程序的崩溃

结果想要加上try catch时却又提示

No calls to throwing functions occur within ‘try’ expression

所以算了,还是不去加了。

还是删除旧程序,重新安装新程序吧。

然后重新安装程序,即可解决问题。

转载请注明:在路上 » [已解决]NSInvalidUnarchiveOperationException NSKeyedUnarchiver decodeObjectForKey  cannot decode object of class for key  NS.objects

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

网友最新评论 (1)

  1. 你这也叫解决?
    。。。7年前 (2018-04-03)回复
94 queries in 0.194 seconds, using 22.09MB memory