https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
a

Asad Mukhtar

08/25/2022, 6:56 AM
Hi, everyone can you please let me know, can i use Compose for building Android UI, and swiftUI for IOS in KMM project?
h

hfhbd

08/25/2022, 7:05 AM
First of all: Native Swift support is not supported, because Kotlin does only support Objective-C. Next, it depends on your definition of Compose 😄 If you mean Compose UI, it is a UI framework which stable version currently does not support iOS. Alpha versions of JetBrains Compose support iOS and for SwiftUI you need the wrapper: https://developer.apple.com/tutorials/swiftui/interfacing-with-uikit. See the ios examples https://github.com/JetBrains/compose-jb/tree/master/experimental/examples/falling-balls-mpp. Alternatively, you can share everything but UI, so Data, Business logic, ViewModels, Networking, etc with Kotlin Multiplatform and implement your UI with Compose UI on Android/Desktop, and implement the UI for iOS using SwiftUI. This is done in my sample https://github.com/hfhbd/ComposeTodo or at https://github.com/joreilly/PeopleInSpace
k

Konstantin Tskhovrebov

08/25/2022, 7:35 AM
p

Paul Woitaschek

08/25/2022, 7:39 AM
I wonder though if it's possible to use compose without compose UI and consume a composable function from swift.
h

hfhbd

08/25/2022, 7:45 AM
I guess, it is possible, and what Cash does with redwood https://jakewharton.com/multiplatform-compose-and-gradle-module-metadata-abuse/. But you still have to implement the Swift compose applier. Open question is the implementation because lacking swift support from Kotlin. And what do you want to share with compose? For data, you could use Flows instead, which works almost out of the box with Swift.
p

Paul Woitaschek

08/25/2022, 7:46 AM
A view state. Using regular composables on droid and molecule on iOS should work
h

hfhbd

08/25/2022, 8:07 AM
I guess redwood does exactly this. It fits perfectly into cash projects with molecule. Just wait until september 1: https://nyc.droidcon.com/jake-wharton/
32 Views