I have a JSON parsing class like so
class JSONParser: NSObject {
let newJSONDecoder : JSONDecoder
let data : Data
init(decoder: JSONDecoder, data: Data, model: ) {
self.newJSONDecoder = JSONDecoder()
self.data = data
}
}
The goal is to have the model parameter be a class that can take in any data and any model and create an object and return it to the calling class instance. EG below
let jsonParser = JSONParser(myDecoder, data, struct)
let parsedArray = jsonParser.createJSONArray()
Can I pass in a struct to the JSONParser init method of type struct and not of type struct "class" name (eg ModelStruct)?
Eventually, the struct parameter should get used in this function
try newJSONDecoder.decode(model.self, from:data!), so the second issue is how to get it into that function - won't work if printed as a String.
JSONDecoder?