为什么 class 不符合 NSCoding?

Why doesn't class conform to NSCoding?

我收到以下错误:

Type 'TestClass' does not conform to protocol 'NSCoding'

NSCoding 只需要两种方法,而且两种方法都有。我错过了什么?

class TestClass: NSObject, NSCoding {
    var Property1:Double? = 0.00

    required init(code aDecoder: NSCoder) {
        if let priceCoded = aDecoder.decodeObjectForKey("Property1") as? Double {
            self.Property1 = priceCoded
        }
    }

    func encodeWithCoder(aCoder: NSCoder){
        if let priceEncoded = self.Property1 {
            aCoder.encodeObject(priceEncoded, forKey: "Property1")
        }
    }
}

您在参数名称中遗漏了 'r' 符号。将您的初始化程序名称更新为:

required init(coder aDecoder: NSCoder)

它会起作用

我正在用这个解决这个问题:-

required init?(coder aDecoder: NSCoder) {

}
func encodeWithCoder(aCoder: NSCoder) {

}

XCode 8.0 (8A218a) , swift 3