2

I have moved part of my code into a separate framework, and that framework contains a model used by the app to persist data to CoreData. Now when I try to launch the app, and it tries to restore state from CoreData, I get the following error.

2020-06-17 21:01:42.549851-0400 Project[17576:2986881] [error] fault: exception raised during multi-threaded fetch *** -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (Project.Track) for key (NS.objects) because no class named "Project.Track" was found; the class needs to be defined in source code or linked in from a library (ensure the class is part of the correct target). If the class was renamed, use setClassName:forClass: to add a class translation mapping to NSKeyedUnarchiver ({
    "__NSCoderInternalErrorCode" = 4864;
})

It worked as expected before splitting the code off into a separate framework. I have tried to import the framework into each class that uses CD, and I have even tried to map it to the class' new namespace using Framework.Track, but I am still getting this error. Has anyone encountered this, and if so can you share some insight into resolving the error? I appreciate any help.

diatrevolo
  • 2,782
  • 26
  • 45

1 Answers1

2

I found the answer, it was as specified by the exception. I just had to set the class name using the app's namespace to the new imported class, as so:

NSKeyedUnarchiver.setClass(Track.self, forClassName: "Project.Track")

Hope that helps someone.

diatrevolo
  • 2,782
  • 26
  • 45