swift NSCoder不要在widget中解码

时间:2016-07-02 18:21:34

标签: ios xcode swift today-extension nscoder

我有一个在主机应用程序和小部件中执行的代码。所有工作都在主应用程序中,但在小部件中有一行 - 没有

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)
}

此行中的小部件崩溃 mode = NSKeyedUnarchiver.unarchiveObject(with: saved as Data) as! [LEDMode]

调试器中的

消息

2016-07-02 21:09:27.276947 LEDWidget [4616:272955] * Terminatingapp由于未捕获的异常'NSInvalidUnarchiveOperationException',  原因:'* - [NSKeyedUnarchiver decodeObjectForKey:]: 无法解码类(LEDControl.SingleColor)的对象(NS.objects); 该类可以在源代码中定义,也可以在未链接的库中定义

class SingleColor diclared

class SingleColor: LEDMode

类LEDMode diclared

class LEDMode: NSObject, NSCoding

0 个答案:

没有答案