How to hold objects with lifecycle inside State? #3205
-
Context: Problem: Is it possible to get something similar with TCA State? Or maybe there is something else that will help solve my problem without manually managing the lifecycle (which is not always possible) Example: |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Somewhat solved this using this trick, not sure it's the best way tho
|
Beta Was this translation helpful? Give feedback.
-
Hi @romanatexn, yes this is essentially the way to do it. The lifecycle of a TCA feature can be modeled by a long living effect since when TCA features are dismissed their effects are torn down (assuming you are using the presentation tools of the library, e.g. However, there are some things you should consider to improve this. First, if you are sending the So really you should introduce a kind of case .onFirstAppear:
return .run { @MainActor _ in
viewModel.create()
try? await Task.never()
viewModel.clear()
} |
Beta Was this translation helpful? Give feedback.
Somewhat solved this using this trick, not sure it's the best way tho