Swift only way to prevent NSKeyedUnarchiver.decodeObject crash?

后端 未结 4 549
佛祖请我去吃肉
佛祖请我去吃肉 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:54

    another way is to fix the name of the class used for NSCoding. You simply have to use:

    • NSKeyedArchiver.setClassName("List", forClass: List.self before serializing
    • NSKeyedUnarchiver.setClass(List.self, forClassName: "List") before deserializing

    wherever needed.

    Looks like iOS extensions prefix the class name with the extension's name.

提交回复
热议问题