I'm building a macOS application to interact via a web API with a server another company runs. I have no existing users, so I can target an arbitrary version of macOS (currently 10.15; I'm running 10.15.4). This server provides thousands of objects as JSON. Sounds like a perfect match for JSONSerialization and NSBatchInsertRequest, as discussed in the WWDC 2019 session Making Apps with Core Data.
The problem I have is most of the JSON keys have dashes in them, and Core Data does not allow dashes in attribute names. Thus, those attributes don't make it into my Core Data objects. Before trying to move to Core Data, I was using structs with a CodingKeys enum combined with JSONDecoder to pull the data in as Swift objects.
An example of the structs I have been using:
struct objectMetadata: Codable {
let lock:String
let lastModifyTime:Date
let lastModifier:String
let creationTime:Date
let creator:String
enum CodingKeys : String, CodingKey {
case lock
case lastModifyTime = "last-modify-time"
case lastModifier = "last-modifier"
case creationTime = "creation-time"
case creator
}
}
I assume I have to do something similar here. How would I control the exact way a JSON blob is converted to an instance of an entity?