I have a code that is executed in the host application and widget. All works in the main application, but one line in the widget - no
required init(coder aDecoder: NSCoder) {
name = aDecoder.decodeObject(forKey: "Name") as! String
ip[0] = UInt8(aDecoder.decodeInteger(forKey: "IP0"))
ip[1] = UInt8(aDecoder.decodeInteger(forKey: "IP1"))
ip[2] = UInt8(aDecoder.decodeInteger(forKey: "IP2"))
ip[3] = UInt8(aDecoder.decodeInteger(forKey: "IP3"))
NSKeyedUnarchiver.setClass(LEDMode.self, forClassName: "LEDMode")
if let saved = aDecoder.decodeObject(forKey: "Mode") as? NSData {
mode = NSKeyedUnarchiver.unarchiveObject(with: saved as Data) as! [LEDMode]
}
client = getTCPClient(ip)
}
widget crash in this line
mode = NSKeyedUnarchiver.unarchiveObject(with: saved as Data) as! [LEDMode]
message in debugger
2016-07-02 21:09:27.276947 LEDWidget[4616:272955] * Terminatingapp due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: '* -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (LEDControl.SingleColor) for key (NS.objects); the class may be defined in source code or a library that is not linked
class SingleColor diclared
class SingleColor: LEDMode
class LEDMode diclared
class LEDMode: NSObject, NSCoding