-
struct SomeFeature: ReducerProtocol {
struct State: Equatable {
@BindingState var someText: String = ""
}
enum Action: BindableAction {
case binding(BindingAction<State>)
}
func reduce(into state: inout State, action: Action) -> EffectTask<Action> {
switch action {
case .binding(\.someText):
return .none
case .binding:
return .none
}
}
} Hello. I am new to TCA. Thank you 🙇♂️ |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi @jkay-kim, yes something is missing from your code. You should have seen a purple warning in Xcode letting you know that something was wrong when you typed into the text field. Did you not? To fix this you have to use the struct SomeFeature: ReducerProtocol {
struct State: Equatable {
@BindingState var someText: String = ""
}
enum Action: BindableAction {
case binding(BindingAction<State>)
}
var body: some ReducerProtocolOf<Self> {
BindingReducer()
Reduce { state, action in
switch action {
case .binding(\.someText):
return .none
case .binding:
return .none
}
}
}
} |
Beta Was this translation helpful? Give feedback.
-
@mbrandonw Thank you for your answer. |
Beta Was this translation helpful? Give feedback.
Hi @jkay-kim, yes something is missing from your code. You should have seen a purple warning in Xcode letting you know that something was wrong when you typed into the text field. Did you not?
To fix this you have to use the
BindingReducer
. We have an article in the documentation that describes this, but in your case you want this: