为什么我收到“类型‘书签’不符合协议‘可解码’”错误消息?
class Bookmark: Codable {
weak var publication: Publication?
var indexPath: [Int]
var locationInText = 0
enum CodingKeys: String, CodingKey {
case indexPath
case locationInText
}
init(publication: Publication?, indexPath: [Int]) {
self.publication = publication
self.indexPath = indexPath
}
}
我不想保存出版物变量,因为出版物拥有书签,但书签需要知道它属于哪个出版物。Publication 的 decode init 会将书签引用设置为自身。