I would like to ask you some help again. This time I'm struggling with ObservableObject. My main goal is to have a single json parser in a single file which would work for all kind of models.
So.. I want to pass a model name and a file name as arguments to a method declared as ObservableObject.
public class JsonParser: ObservableObject {
@Published var result = [articleModel]()
init() {
load(jsonFileName: "words")
}
I would like to call it like that:
@ObservedObject var myResult = JsonParser(jsonFile: "words", model: "articleModel")
The problem is.. I do not know how to pass the model and the file name as arguments in this specific SwiftUI framework. If somebody could give me some hints, I would appreciate that a lot.
articleModelto be the type of objects in theresultarray? That's not possible in Swift, types need to be known at compile time, there no dynamic typing.ObservableObjectdoesn't change anything related to your actual problem.