为什么我会收到"类型‘Bookmark’不符合协议‘Decodable’"的错误消息?
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
}
}
我不想保存出版物变量,因为该出版物拥有书签,但书签需要知道它属于哪个出版物.发布的decode init将书签引用设置为自身.