I have been working on a project and have an existing object I am using. I am trying to find a simply way to save, retrieve and delete a list of these objects in Core Data.
Here is my object
import Foundation
class Book : Codable {
var coverIndex:Int?
var authorName:[String]?
var title:String?
var editionCount:Int?
var firstPublishYear:Int?
var key: String?
var publishPlace:[String]?
var publisher:[String]?
public enum BookResponseCodingKeys: String, CodingKey {
case coverIndex = "cover_i"
case authorName = "author_name"
case editionCount = "edition_count"
case firstPublishYear = "first_publish_year"
case key = "key"
case title = "title"
case publishPlace = "publish_place"
case publisher = "publisher"
}
public required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: BookResponseCodingKeys.self)
self.coverIndex = try container.decodeIfPresent(Int.self, forKey: .coverIndex)
self.authorName = try container.decodeIfPresent([String].self, forKey: .authorName)
self.editionCount = try container.decodeIfPresent(Int.self, forKey: .editionCount)
self.firstPublishYear = try container.decodeIfPresent(Int.self, forKey: .firstPublishYear)
self.key = try container.decodeIfPresent(String.self, forKey: .key)
self.title = try container.decodeIfPresent(String.self, forKey: .title)
self.publishPlace = try container.decodeIfPresent([String].self, forKey: .publishPlace)
self.publisher = try container.decodeIfPresent([String].self, forKey: .publisher)
}
}
What is the most straightforward to save this in Core Data (or to map it to a Core Data model.)


