Hi. I have a project with multiple modules in my p...
# kotlin-native
y
Hi. I have a project with multiple modules in my project. I have a ‘core’ module, and ‘feature’ modules. The core module initializes a Singleton ‘object’ that is later being consumed by the ‘feature’ module(works as expected for Android) .However,I have noticed that the singleton object is being instantiated twice in iOS. when I looked deeper into this, I noticed that because both of the pods (core, and feature) were added to the iOS app, the ‘core’ module is being added twice(?) - once by the pod itself, and once again by the ‘feature’ module that is dependent on the ‘core’ module in KMM. Is there a way of dealing with this? How can I share information between modules if this is indeed a limitation? I can try to share data by writing to a db of some sort, but is this really the only option?
s
Each compiled Kotlin framework is its own little world. What people normally do in this situation is have an umbrella framework that includes all of the modules an app needs. In your case would look like this. App -> shared -> feature1..x->core
y
@Sam thanks! and yeah, I saw that option, However, in my case we are aiming for a modular SDK, kinda similar to Ktor in that regard, where you can import features as you desire. An umbrella will not solve this, unfortunately… 😞
s
If your consumers are in house, you can require them to create their own umbrella frameworks per project. Otherwise Kotlin probably isn’t a good fit for your needs right now. Each framework has its own copy of the Kotlin runtime embedded in it. There are other issues like, Framework1.ClassA is not the same as Framework2’s ClassA. You can't pass an instance of one into the other from Swift.
y
well, that’s a shame… 🤔