Hi,
Overview
- I have a file
CarComponents.swiftin 3 targets (Xcode targets) - App, Unit tests and Extension targets - When I ran the extension target scheme and
NSKeyedUnarchiver.unarchivedObjectis executed an error is thrown
Error:
Error Domain=NSCocoaErrorDomain Code=4864 "*** -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (MyApp.CarComponents) for key (root) because no class named "MyApp.CarComponents" 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" UserInfo={NSDebugDescription=*** -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (MyApp.CarComponents) for key (root) because no class named "MyApp.CarComponents" 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}
My understanding
It is looking for MyApp.CarComponents, but is being run from an extension target
(lldb) po CarComponents.self
DemoExtension.CarComponents
Questions
- How to resolve this issue?
- Or am I missing something bigger?
Code
nonisolated class CarComponentsValueTransformer: ValueTransformer {
....
....
override public func reverseTransformedValue(_ value: Any?) -> Any? {
guard let data = value as? Data else { return nil }
do {
let CarComponents = try NSKeyedUnarchiver.unarchivedObject(
ofClass: CarComponents.self,
from: data as Data
)
return CarComponents
} catch {
assertionFailure("Failed to transform `Data` to `CarComponents`")
return nil
}
}
}