Swift only way to prevent NSKeyedUnarchiver.decodeObject crash?

后端 未结 4 546
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-13 18:10

NSKeyedUnarchiver.decodeObject will cause a crash / SIGABRT if the original class is unknown. The only solution I have seen to catching this issue

4条回答
  •  天命终不由人
    2020-12-13 18:43

    Actually, it's the reason which we should dig deeply matters. There's a possible, you create a archive path named xxx.archive, then you unarchive from the path(xxx.archive), now everything is ok. But if change target name, when you unarchive, the crash occurred!!! It's because archive&unarchive the different object(the truth is we archive&unarchive target.obj, not just the obj). so simple way is to delete the archive path or just use a different archive path. And then we should consider how avoid the crash, try-catch is our helper mentioned by rintaro.

提交回复
热议问题