Are there any recommendations on how to use Multip...
# swift-export
h
Are there any recommendations on how to use Multiplatform ViewModels with Swift Export yet?
f
That's a good question, I’m trying to migrate my playground from skie to swift export and that’s not easy.
Some API that’s kotlin can export easily in objc can’t be in swift
h
FWIW AI spit this out for me. Has been working pretty well so far
*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)") } } } }
f
It’s totaly possible to reproduce SKIE with the flow, your snippet is a little example. skie.touchlab.co/features/flows-in-swiftui
h
Does Skie support swift export?
f
No, it won’t.
👍 1
By reproducing, I mean the behavior of SKIE but with Swift export.
👍 1
a
Hello there. The simplest way to connect androidx Vm with SUI is something like this - github.com/joreilly/PeopleInSpace/pull/524/changes#…, as demonstrated by @John O'Reilly (quite close to the snippet made by your AI) In our tutorials for using androidx VM from SUI we as Kotlin Ecosystem actually recommend using github.com/rickclephas/KMP-ObservableViewModel by @Rick Clephas, as it helps with a lot of boilerplate. RN we are discussing, what would be the correct approach of providing a support for KMP-ObservableVM inside the Swift Export, stay tuned 😉 But no timeframe on that integration