My question is a conceptual question.
I have the following code:
struct CategoriesList : View {
@State private var categories: [CategoryMetadata] = []
var body: some View {
NavigationView {
List(self.categories) { category in
NavigationButton(destination: PostsList(category: category)) {
CategoryRow(category: category)
}
}
}.navigationBarTitle(Text("Categorie"))
}
}
That simply compose my UI using a list of elements (categories) and I have a state associated with my view that auto-update the view when it changes.
It's all fancy and nice but for me it's not clear WHO should fire the network request to fill the model.
I understood the bindings and the @state idea, but, in general, how should I architecture the code to have the models I need at the beginning?
In the old approach I would have implemented this behavior in the viewDidLoad, but with the new paradigm of SwiftUI, what is the best approach to get my data?