Best practices for SwiftUI state variable encapsulation/ Too many state variables in a complicated view

338 views Asked by At

I'm use to have a class for several complex subviews in a view. Each can encapsulate it's own state. SwiftUI will let you refactor a long view function into subviews but I have not found anything other than passing @Binding variables through the views.

I keep ending up with a lot of state variables on the main view. Ideally what I would like would be if I could reference a subview of the main and directly set it's state like this

mainView.bottomPane.odometer.speed = 55

Is this possible? If not are there other ways around large chunks of State variables in the main form?

0

There are 0 answers