問(wèn)題:
[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (Installation) for key (root); the class may be defined in source code or a library that is not linked
一般出現(xiàn)在用archive序列化存儲(chǔ)一個(gè)對(duì)象A,然后后來(lái)的某個(gè)版本中在對(duì)象A中添加了屬性。然后解檔老的序列化數(shù)據(jù)時(shí)crash
NSKeyedArchiver.setClassName("Employee", for: Employee.self)
//before serializing
let employeeData = NSKeyedArchiver.archivedData(withRootObject: employee)
NSKeyedUnarchiver.setClass(Employee.self, forClassName: "Employee")
//before deserializing
NSKeyedUnarchiver.unarchiveObject(with: decoded) as? Employee