-
Hi everyone, I’m having an issue where resetting a list of counters in TCA doesn’t update the SwiftUI view, even though _printChanges() shows the state updating correctly. Looking for help! Problem
What I’ve Noticed
Questions
Info
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
This works
Not sure why it needs map instead of just state.counters = state.defaultCounters. I thought structs being copied would avoid issues, and _printChanges() shows the change, so I’m confused why state.counters = state.defaultCounters doesn’t update the view. |
Beta Was this translation helpful? Give feedback.
-
This is starting to look to me like a soundness issue with You get a similarly broken experience with this simpler wrapper around @Reducer
struct SingleCounterFeature {
@ObservableState
struct State: Equatable {
let `default` = CounterFeature.State(id: UUID(), count: 0)
var counter: CounterFeature.State?
}
enum Action {
case reset
case counter(CounterFeature.Action)
}
var body: some ReducerOf<Self> {
Reduce { state, action in
switch action {
case .reset:
state.counter = state.default
// Uncomment to work around the issue:
//state.counter = .init(id: state.default.id, count: state.default.count)
return .none
case .counter:
return .none
}
}
.ifLet(\.counter, action: \.counter) {
CounterFeature()
}
._printChanges()
}
}
struct SingleFeatureView: View {
let store: StoreOf<SingleCounterFeature>
var body: some View {
VStack {
Button("Reset Counters") {
store.send(.reset)
}
if let store = store.scope(state: \.counter, action: \.counter) {
CounterView(store: store)
}
}
}
} The reason assigning with @ObservationStateIgnored var _$observationRegistrar = ComposableArchitecture.ObservationStateRegistrar()
public var _$id: ComposableArchitecture.ObservableStateID {
_$observationRegistrar.id
} whose identity ( Having thought about this a while, I can't see how I'd like to bring to attention this quote by John McCall because it feels like it's exactly the issue
(There are generally many good comments around the topic if you browse up and down that same Swift Forums thread, btw.) |
Beta Was this translation helpful? Give feedback.
This is starting to look to me like a soundness issue with
@ObservableState
. It has little or nothing to do withIdentifiedArray
and everything with observation macros silently turningstruct State
into a reference-semantic type! 🤯You get a similarly broken experience with this simpler wrapper around
CounterListFeature
(and …View
):