我看到了几个与我类似的问题;然而,这些与 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(
。也许这与此有关。
我该如何解决这个问题?谢谢!
The encode
Swift 3 中的方法已重命名为
func encode(with aCoder: NSCoder)
当你得到不确定错误你可以很容易地找出缺少哪些所需的方法
- Press ⌘B to build the code.
- Press ⌘4 to show the issue navigator.
- 单击问题行前面的披露三角形。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)