How come setting Data
in a State
turns this app unreactive?
#2308
-
👋 I am probably missing something silly here but in a very little sample app, as soon as I add Is it a bad idea to store binary data in the state for some reason? 🤔 Full code here, but the gist of what is going on is here: struct RootFeature: ReducerProtocol {
struct State {
var latestPhotoData: Data?
var count: Int
}
enum Action {
case incrementButtonTapped
case loadDummyButtonTapped
}
var body: some ReducerProtocolOf<Self> {
Reduce<State, Action> { state, action in
switch action {
case .incrementButtonTapped:
state.count += 1
return .none
case .loadDummyButtonTapped:
guard let image = UIImage(named: "DummyImage"),
let imageData = image.jpegData(compressionQuality: 1)
else {
fatalError("No image found.")
}
state.latestPhotoData = imageData
print("Set data")
return .none
}
}
}
}
extension RootFeature.State: Equatable {}
extension RootFeature.Action: Equatable {} Thanks 🙏 Data-TCA.mp4 |
Beta Was this translation helpful? Give feedback.
Answered by
mbrandonw
Jul 19, 2023
Replies: 1 comment 4 replies
-
@dirtyhenry I'm not able to reproduce that using your project in Xcode 15 beta 4 (the view is completely replaced with "PHOTO"). Do you have more instructions on how to repro? |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @dirtyhenry, I was able to reproduce this in iOS 16, though it does seem fixed in iOS 17 somehow.
I can't explain it, but something about
Data
andWithViewStore
makes SwiftUI get into a very weird state. You can avoidWithViewState
by using@ObservedObject
directly:That fixes the problem somehow.
Additionally I would say that generally it is not necessary to store
Data
in state. What is the reason to store the data in state? Is it needed to …