Horatio Thomas
09/15/2026, 12:02 PMFrançois
09/16/2026, 11:55 AMFrançois
09/16/2026, 12:02 PMHoratio Thomas
09/17/2026, 7:03 AM*extension* View {
/// Mirrors a Kotlin StateFlow into binding for as long as the view is alive.
///
/// Swift export bridges StateFlow as an AsyncSequence, so views keep a plain
/// @State copy of the latest value instead of observing the ViewModel itself.
*func* mirroring<Element>(
_ flow: *any* KotlinTypedStateFlow<Element>,
into binding: Binding<Element?>
) -> *some* View {
task {
*do* {
for try *await* value *in* flow.asAsyncSequence() {
binding.wrappedValue = value
}
} catch *is* CancellationError {
// Expected when the view's task is torn down.
} *catch* {
assertionFailure("StateFlow observation failed: \(error)")
}
}
}
}François
09/17/2026, 7:48 AMHoratio Thomas
09/17/2026, 7:49 AMFrançois
09/17/2026, 7:52 AMFrançois
09/17/2026, 7:52 AMArtem Olkov
10/06/2026, 11:23 AM