[ad_1]
Right here is an alternate, Binding wants a SwiftUI View to remain up to date due to its DynamicProperty conformance
import SwiftUI
struct OnboardingStateView: View {
@StateObject var vm: OnboardingStateController = OnboardingStateController()
var physique: some View {
VStack{
Button("go", motion: {
vm.go()
})
Textual content(vm.shouldHide.description)
}
}
}
remaining class OnboardingStateController: ObservableObject {
@Revealed var shouldHide: Bool = false
func go() {
//This makes use of a completion handler vs passing the `Binding`
MyLogic.fooBar(
shouldHide: { shouldHide in
self.shouldHide = shouldHide
}
)
}
}
struct MyLogic {
static func fooBar(shouldHide: (Bool) -> Void) {
let worth = Bool.random() //.. SomeClass({ shouldHide.wrappedValue = true })
shouldHide(worth)
}
}
struct OnboardingStateView_Previews: PreviewProvider {
static var previews: some View {
OnboardingStateView()
}
}
[ad_2]
