I developed a framework in Swift and designed a screen/view via SwiftUI.
SwiftUI view will be presented on top of the Window by the class written in Swift.
Now I need to pass the data from the Swift class to SwiftUI.
Could one any help to know the best practice to pass the data to show the progress from Swift class to Swift UI.
func A () {}
func B () {
// score will get updated frequently
score = ....
ScorePresenter().presentScoreUI()
}
}
import SwiftUI
struct ScorePresenter: {
func presentScoreUI() {
let hostController = UIHostingController(rootView: ScoreUI())
hostController = .overCurrentContext
topViewController()!.present(hostController, animated: true, completion: nil)
}
}
struct ScoreUI: View {
var score = 1
Text(score).foregroundColor(.green)
}
When ever score changes in Score class ScoreUI must be updated accordingly.