[英]Does not conform to protocol 'NSCoding' - Swift 3
我見過幾個類似於我的問題; 然而,那些與swift 2/1有關,我目前正在使用swift 3.我相信Apple已經稍微改變了它。
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(
。也許這與它有關)。
我該如何解決這個問題? 謝謝!
Swift 3中的encode
方法已重命名為
func encode(with aCoder: NSCoder)
當您收到不符合的錯誤時,您可以輕松找出缺少哪些必需的方法
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.