我看到了几个与我的问题类似的问题,但是那些都涉及Swift 2/1,而我目前正在使用Swift 3。我相信苹果公司对它进行了轻微的更改。
class Person: NSObject, NSCoding {
var signature: UIImage
init(signature: UIImage) {
self.signature = signature
}
required convenience init(coder aDecoder: NSCoder) {
let signature = aDecoder.decodeObject(forKey: "signature") as! UIImage
self.init(signature: signature)
}
func encodeWithCoder(aCoder: NSCoder) {
aCoder.encode(signature, forKey: "signature")
}
}
你会注意到Swift 3现在强制我使用
required convenience init(
而不是required init(
。可能与此有关。我该如何解决这个问题?谢谢!