Friday, November 6, 2026
HomeiOS Developmentios - Methods to move Binding of @printed variable in perform from...

ios – Methods to move Binding of @printed variable in perform from ObservedObject

[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]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments