I have a pretty trivial Swift app that has a model class named DemoNote
. An array of DemoNote
instances is read/written via keyed archiving. This w
Moving DemoNote
from the app to a framework did change the module name, which meant that NSKeyedUnarchiver
couldn't find instances of the archived class due to a name mismatch. The fix was to add this line before unarchiving:
NSKeyedUnarchiver.setClass(DemoNote.self, forClassName: "DemoNotesSwift.DemoNote")
In this case, DemoNote.self
gets the current full class name, and DemoNotesSwift.DemoNote
is what the class used to be called when it was part of the app.
This was only necessary because I had previously existing data that I wanted to keep.