Where are you storing your data? Read up on ObservableObject, @Published vars, and @EnvironmentObjects.
You basically create a data store (it's just a struct) somewhere, and set some vars as @Published. Then, you can either pass the data store through your View hierarchy as an @EnvironmentObject, or you can observe the variables. Call your API and store the updated data in the data store, and update your published vars. Once the published vars have changed, anything "observing" those vars will automatically update to show the new data.
Example:
let modelData: ModelData = ModelData()
class ModelData : ObservableObject {
@Published var latestData: Dictionary<String, Any> = getUpdatedData()
@Published var latestTitle: String = "Nothing yet"
}
@main
struct OpenAIApp : App {
@EnvironmentObject var modelData: ModelData
var body: some Scene {
Text(modelData.latestTitle)
}
}
That should work, but just read up on those things I mentioned so you get an understanding of how it works, and can apply it to your code.