0

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
MacSergey
  • 15
  • 7
  • @Dershowitz123 in SingleColor required init(coder aDecoder: NSCoder) { super.init(coder: aDecoder) for i in 0...2 { color[i] = UInt8(aDecoder.decodeInteger(forKey: "color\(i)")) } } – MacSergey Jul 02 '16 at 18:32
  • @Dershowitz123 if I add super.init() to LEDMode - error "Property 'self.client' not initiallized at super.init call" – MacSergey Jul 02 '16 at 18:34

0 Answers0