Is it possible to use SwiftUI in the ios source se...
# multiplatform
Is it possible to use SwiftUI in the ios source set of a multiplatform module?
AFAICS, the answer must be no because SwiftUI is a Swift-only library, but Kotlin can only access Objective-C interfaces.
No, you can't use SwiftUI in this way. The way to interface SwiftUI wth KMM is to keep the SwiftUI View layer in Swift, and then write (or 'borrow') some Swift code to consume a Kotlin
and bridge it to the iOS 'Combine' reactive framework. Use this to bind the SwiftUI delcaration to View-Models of your KMM
This method can lead to the 'gold standard' Mobile experience; where each platform is using its true native UI, while the logic (including presentation logic) is shared.
another interesting option, in this context of approach @darkmoon_uk describes, is using
Yeah that's what we're doing but our kmp code is in another repo from our native so looking for solutions to improve the dev ex. It's simple enough for android to add a module next to the kmm code but wondering how to locate the swift ui code close to the multiplatform code.
Trying to avoid publishing all our kmp modules for every change and replicate the android experience where you can point to source
In an iOS app, the multiplatform code is an ObjectiveC-compiled framework, so any change to the multiplatform code needs a new compilation. Ideally you want to make the multiplatform code stable first, by testing it with the Android app.
I suggest to work on the iOS side only when the multiplatform code is stable, so it doesn’t need recompilations. In a multiplatform project, the priority is to stabilize the shared-code first.
You can also keep some swift code in your KMM repo for the UI, then statically link your KMM framework to your swift framework either manually or via cocoapods.
But if I now try to link this swift framework to my app won't I end up reincluding kotlin dependencies for every swift module linked this way?
@bnvinay92 not sure what you mean. Can you explain your use case better?