https://kotlinlang.org logo
#touchlab-tools
Title
# touchlab-tools
j

John O'Reilly

03/21/2024, 8:59 AM
Now that androidx
ViewModel
can be used in KMP code I was just wondering if there is any way with SKIE to get functionality KMMViewModel provides to map
StateFlow
to properties in Swift?
s

Stylianos Gakis

03/21/2024, 9:02 AM
How is that property used as opposed to using the AsyncSequence that Skie generates for you? Is it that KMMVM library does that plus also collects that sequence and stores it in a property automatically for you?
j

John O'Reilly

03/21/2024, 9:04 AM
yeah, pretty much .....you can see examples of it in following https://github.com/joreilly/BikeShare/blob/main/ios/BikeShare/BikeShare/ContentView.swift
I guess some kind of helper could be added that does that
s

Stylianos Gakis

03/21/2024, 9:08 AM
Ah I see, you get the VM and you can just do
vm.stateFlowVal
and you get it ready to use. I wonder if Skie has goals for such tight integrations with StateFlows. Also what if you do not want the StateFlow as a property but as a normal AsyncSequence for other callers? Is this an opt-in feature in that library too?
f

Filip Dolník

03/21/2024, 9:11 AM
Hi! In theory SKIE can generate any Swift or Kotlin code based on the project code. So yes, there is a way. However, such functionality is technically out of scope for SKIE because SKIE focuses on the language itself and is currently architecture agnostic. On the other hand, this does not mean we will not consider it but it’s something we have to discuss internally first. It would certainly be an opt-in feature because not everyone would use it (similarly to what we have with the default arguments). Plus we will have to weigh the implementation complexity to the added benefits.
s

Stylianos Gakis

03/21/2024, 9:12 AM
Also I think it’s be good to try and see how much code is it to do this yourself on a project and if it’s trivial the docs could just provide a snippet and leave it at that. At least for now
j

John O'Reilly

03/21/2024, 9:37 AM
In the case of KMM-ViewModel it also uses it's own custom
MutableStateFlow
in shared code to allow this
this is what I've tried so far btw.....haven't looked yet at lifecycle aspects https://x.com/joreilly/status/1770735472114905257?s=20
5 Views