A
quick (spoiler, its not quick) question on SkieSwiftFlow, at the moment there is no nice way to get a flow to play nicely with SwiftUI? like you get out of the box with Compose.
For example in compose, i would usually do something like:
@Compose
fun coolView(viewModel: CoolViewModel) {
val coolValue = viewModel.fooFlow.collectAsState()
....
Whereas in swift, really i would like to be able to do something like this:
struct CoolView: View {
let viewModel: CoolViewModel
@State var coolValue = viewModel.fooFlow.collectAsState()
....
I was just wondering if anybody came up with a smart extension for this?
extension SkieSwiftFlow {
func collectValue(callback: @escaping (_ value: T) -> Void) {
Task.init {
for await awaitedValue in self {
callback(awaitedValue)
}
}
}
}
Then you could. do something like:
struct CoolView: View {
let viewModel: CoolViewModel
@State var coolValue: Bool = false
init (viewModel: CoolViewModel) {
self.viewModel = viewModel
viewModel.fooFlow.collectValue {
self.coolValue = $0
}
}
....
Sorry for the essay, but how else do people collect values from the SKIE flow? i saw the mainActor stuff, but it would be noisy for lots of values, unless you created your own wrapper viewmodel and did it there but im a beleiver that the Kotlin generated view model should be useable from native without a wrapper.