Is there recommended way right now to pass state f...
# compose-ios
j
Is there recommended way right now to pass state from a Compose function to a
UIKitViewController
(that is implemented using SwiftUI code in iOS project)? I'm trying to adapt code in https://github.com/touchlab/compose-swiftui-codelab to case where position is periodically updating
r
Recommended: None that I am yet aware of My talk at droidcon will cover this, here I have an example for SwiftUi using State flow for that and one for UiKit updating every value on update, both without using a Viewmodel. But you could also supercharge it with a Viewmodel. https://github.com/rschattauer/compose_multiplatform
j
thanks, will take a a look at that
r
Within my presentation (also in that repo) I also have the link to a blogpost of touchlabs way of doing it via Viewmodel.
👍 1
j
btw what was the article you mentioned about doing using a view model....I saw following but was this different one? https://touchlab.co/jetpack-compose-ios-interop
r
No, this is the one I meant, yeah.
j
ah, sorry, I missed that that was talk about using a view model
the background to this btw is that I'm trying to use this approach for PeopleInSpace and in particular the ISS position map.....this particular sample is using Swift ViewModel which maybe complicates things a little here
but probably way around that too
I'm sensing that maybe I'm over complicating things a bit 😃
anyway, will make sure to attend your session next week!
yeah, seems like viewmodel approach is working well for what I need here
r
I would be honoured. Great, that you succeeded, just saw your blogpost about it :)
s
Besides ViewModel I also have being building a "state delegate interface", basically a interface that has for each Composable state parameter a update function, when it changes I call the update function, later, this interface is implemented on a ObservableObject. This way, you can easily have the multiple components in the same screen, with compose state changes be notified to each SwiftUI component without needing to use viewmodel keys.