0

I have an exception using this code ;

let readingData = NSKeyedUnarchiver.unarchiveObjectWithData(data) as? [ExternalProjectClass]

The message in the console :

cannot decode object of class (MyIOSApp.ExternalProjectClass) for key (NS.objects); the class may be defined in source code or a library that is not linked'

I use 'ExternalProjectClass' class in 2 project in the same workplace. In MyApp application (mac version). Otherwise I can use my class normally, I only have problems with coding.

I know how poor is my english. I hope somebody can help me.

Regards.

Sébastien REMY
  • 2,399
  • 21
  • 39

1 Answers1

0

Swift class names have namespaces, and the default namespace is module name. So if you move the archive from an app to another, the class name differs.

You could put @objc(ExternalProjectClass) attribute on your class, so it is called ExternalProjectClass as far as NSCoder considers.

@objc(ExternalProjectClass) class ExternalProjectClass: NSObject, NSCoding { ... }
Guoye Zhang
  • 499
  • 4
  • 9