Hey there, I have a Compose Multiplatform project ...
# multiplatform
m
Hey there, I have a Compose Multiplatform project with two apps: app1 and app2. Both apps use a shared Kotlin module that contains UI, utilities, and resources. Each app also has its own independent iOS project (iosApp1 and iosApp2). The shared Kotlin module defines interfaces for native iOS services. Whenever I add a new service, I have to implement it separately in both iOS projects. My questions are: 1. Can I create a shared Swift library that depends on the shared Kotlin module (via an XCFramework), implement the iOS-specific services once in that Swift library, and then link it to both iOS projects to avoid duplication? 2. Would this approach cause duplication of code and resources, since the shared Kotlin module is already used in both app1 and app2, and then gets bundled again through the XCFramework into the Swift library?
l
Your question is very specific to compose, so your post probably will get better attention if posted on #CJLTWPH7S.
a
@Moref 1. yes I think you can create an intermediate library which import your shared module, do the logic you need -> and then you only import this framework into your app1 and app2. 2. But if you also import the shared module directly into app1 and app2 you will have duplication of dependencies yes. And worse, if you need to use a common object from shared module and your framework (wrapping your shared module) you won’t be able to do so as explained in this article : https://medium.com/@maruchin/kmm-architecture-4-umbrella-a26a370071d5
m
@Anthony Mamode Thanks for the clarification. So I need to implement the ios interfaces (declared in shared module) natively separately in each ios project, right?
a
I don’t know your specific requirements for your apps, but yes it might be the only way to do it. One remark though, if your two CMP projects are relatively similar, I would suggest to use flavors and targets instead of having two separate projects as it is today. Other point: if you want to create and import a xcframework (in addition to the shared module) it has to be completely isolated from the shared module code (no shared classes, like an external library). If so, it is possible to consume it in your iOS projects, alongside to the shared module.
👍 1