不符合协议'NSCoding' – Swift 3
我看过几个类似于我的问题。 然而,这些都属于迅速2/1,我目前正在使用迅速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(
或许这与它有关)。
我该如何解决这个问题? 谢谢!
Swift 3中的encode
方法已被重命名为
func encode(with aCoder: NSCoder)
当你得到不符合的错误,你可以很容易地找出缺less哪些方法
- 按⌘B构build代码。
- 按⌘4显示问题导航器。
- 点击发行行前面的显示三angular。