0

I am new to SwiftUI and TCA (the composable architecture) and I am having troubles passing a binding var in one state from one view to another. Here's what I'm doing:

In PlaceView I have the following state:

struct PlaceStore: ReducerProtocol {
    struct State: Equatable { 
        var placeSelected: Place?
        var presentingCreatePlace: Bool = false
    }
//etc

}

And I have a CreatePlaceView that is presented as sheet from PlaceView when presentingCreatePlace is true through a button tap.

struct CreatePlaceStore: ReducerProtocol {
    struct State: Equatable {      
        @BindingState var placeSelected: Place?        
    }
  }

I want to pass the placeSelected from PlaceView to CreatePlaceStore as a binding but when I send it through the init of the store, it says that is not expecting a binding. How can I do it?

Joan Cardona
  • 3,463
  • 2
  • 25
  • 43
  • What is `@BindingState`? In any case, usually your "main" view (e.g. the one that represents the screen) will have a `@State` and your "utility" view (e.g. a screen component) will have `@Binding` variable. When you instantiate utility view, you pass your state to assign to that binding. Or you can avoid all that and have @ObservableObject with @Published property used by both main and utility view – timbre timbre Jun 14 '23 at 15:41
  • SwiftUI actually has a reducer built-in, see PreferenceKey, so you don't need TCA's reducer. – malhal Jun 14 '23 at 21:09

0 Answers0