Traditionally, a SwiftUI application will automatically update its view in response to any state changes. This occurs when the @State propertyWrapper detects any updates. I'm curious, is it possible to manually redraw a SwiftUI View, instead of relying on the @State data binding technique ?
You can use an ObservableObject object as model and then call objectWillChange.send() to trigger a refresh
struct MyView : View {
@ObservedObject var model: Model
var body: some View { .. }
}
class Model: ObservableObject {
func reloadView() {
objectWillChange.send()
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With