Hello :wave: I am trying to do a thing and it wor...
# multiplatform
h
Hello 👋 I am trying to do a thing and it works fine on android but I have issues making it work on iOS. I do not know enough about iOS/objectiveC to know if this is a problem with iOS, KMM and/or I am doing something wrong. I have a KMM library which is the "core" of a bunch of other KMM libraries (that are generated) and depend on it with the api keyword. The Android and iOS apps are native and are supposed to include the generated libs and initialise them with the Core dependency. On Android this is no problem, but on iOS (xcframeworks + SPM) it seems all the transitive Core dependencies are different classes (prefixed in Objective C and then aliased to the same name), so I cannot reuse that core dependency.
Copy code
let core = Core(myNativeImplementationOfCoreInterfaces())
let l1 = Lib1Class(core) // works
let l2 = Lib2Class(core) // does not work. Core is technically a different class here with the same name
Does anyone know how to make this work or if this is even possible? I provided a little sketch of the situation.
a
Hm… some key points that may help you: Obj-C requires that all classes in assembly must have unique names. That’s why Obj-C class prefixes are used. So if all libraries are compiled in a single framework or static library, it may be a problem. However, if you are using dynamic frameworks, it can be resolved in Swift by using framework name as a namespace like this:
Copy code
let l1 = Lib1.Lib1Class(core)
let l2 = Lib2.Lib2Class(core)
h
Thank you for that information. I think the dynamic/static thing is important here and I am currently reading up on it. My Problem is however not with Lib1 and Lib2 but with the fact that I have essentially duplicates of the core part and would not be able to reuse the instances (and the dependencies I pass to it which implement interfaces/protocols from the core library).
h
Thank you! that looks exactly like the information I need 👍
For whom it might concern. I could not get the umbrella framework to work. Initially I had a lot of problem with the setup because the klib for Lib1 and Lib2 used the same module name (because they are generated from the same project). I found a way to change this module name eventually, but still it did not come together like I wanted to. I was jumping from obscure issue to obscure issue and the complexity got out of hand. Now I decided to replace the dependency to Core from Lib1 and Lib2 with a generic funtion. So the constructors changed to something like this:
Copy code
class Lib1Class(private val dependency: (Map<String,Any?> , String, String) -> Unit)
And my core dependency has a function with this signature that I can then just pass as a parameter from the native apps.