Hi all ! How is it done to declare an actual funct...
# multiplatform
m
Hi all ! How is it done to declare an actual function in Swift ? I'm using compose multiplatform for the ui but in one point of the app i need to open a iOs native window with some logic using a Swift library. how can I achive that? Thank you in advance 🫶
s
Let Swift create an objective-C binding (@objc annotation) and define cinterop in your gradle build files. This then makes your Swift (objective-c) available to ios-main kotlin code. This can be a bit cumbersome and tricky. I suggest using (manual) dependency injection (DI) and declaring an interface in your common-main Kotlin and implementing that interface(/protocol) in Swift and injecting that implementation into the DI provider (common-main)
👍 5
m
DONE ! works amazing, feel like i just unlock super powers 😄 Thanks for your help
👍 1
s
Which way did you go? The cinterop way or the DI way?
m
I create the interface in common main, and from iOs swift code, i initate the Koin modules, and pass the interface implementation in the initKoin, then i can call it from the shared UI. Is it right ?
💯 1