0

I had a perfectly working app. I wanted to modularize my app because I envision needing bits and pieces of it in other apps. So, I created two frameworks. The two frameworks build fine and my app with the two frameworks embedded in it also builds fine.

My problem comes when I try to unarchive data which has a class that is now in one of my frameworks. I get this error:

reason: '*** -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (myProjecy.MyObject) for key (NS.objects); the class may be defined in source code or a library that is not linked'

In my app I can create instances MyObject fine. All the required methods in the framework are either open or public (or the app wouldn't even build).

What an I missing?

The class in the framework is in Swift and the class trying to unarchive it in is Obj-C. I'm using Xcode 9.

Thanks.

Phantom59
  • 947
  • 1
  • 8
  • 19

1 Answers1

1

OK. I found the problem. Re-visiting this post led me to a solution.

In my case, because the original object was archived while still part of the app and my app specified to use module name then the object was archived with the app's module name. Now, the unarchiver is trying to use the module name in the framework which is what leads to the problem.

So, I basically had to sprinkle a few of these:

NSKeyedUnarchiver.setClass(ClassName.self, forClassName: "AppModule.ClassName")
NSKeyedArchiver.setClassName("AppModule.ClassName", for: ClassName.self)

And everything works fine!

Without this code the the unarchiver tries to use "FrameworkModule.ClassName".

Phantom59
  • 947
  • 1
  • 8
  • 19