Is there a way to consume a swift package library ...
# compose-ios
r
Is there a way to consume a swift package library from kmm shared code without using cocoapods?
p
Yes
That's the official documentation. But it is easier to expose a public interface interface in your
shared
library code, this interface will be implemented in Swift. Then you pass the swift implementation to
shared
. And you avoid all the steps in the page above.
r
Is there any open-source project with an example that you can link
p
I have done it in a couple of projects but don't know your specific use case. Let me see if I can point you an example
r
I'm just trying to add firebase analytics to the ios side
p
https://github.com/pablichjenkov/kmp-amadeus-api/blob/main/shared/src/iosMain/kotlin/com/pablichj/incubator/amadeus/demo/Bindings.kt#L60 Check that, although I just realized I haven't import any library, I am just using :
import SwiftUI
but it shouldn't be a problem to
import AnyLibrary
For firebase I have seen Integrations already. I believe Chris banes tivi App has it integrated, also there is a touchlab example I think.
Also check Joreilly stuff, he might get something: https://github.com/joreilly
m
I've been struggling to figure this out since yesterday and this thread, particularly the Tivi app example, helped me understand this better. Thank you @Pablichjenkov
👍 2
I find the pattern of using Platform bridges quite intriguing, a good next step would be to make this work seamlessly with a DI library.
2
r
Yeah I forgot to comment further on this thread. I ended up using platform bridges, and I got it to work seamlessly with koin.
1
In my
commonMain
I have an expect platform module where I supply all the bridges
expect fun platformModule(analytics: Analytics): Module
🔥 3
I can implement the interface in ios and supply it to the DI graph
KoinApplication.shared.initialize(analytics: AppleAnalytics())
m
Nice. So you have the iOS bridge provided there. Out of curiosity, where do you do the same for Android. I just got my implementation to work and I'm about to integrate it with Koin
r
Application
onCreate
Copy code
override fun onCreate() {
        super.onCreate()
        startKoin {
            androidContext(this@App)
            modules(
                modules = appModule(analytics = AndroidAnalytics()),
            )
        }
    }
👍 1
and this is the def of
appModule
Copy code
fun appModule(analytics: Analytics) =
    listOf(useCaseModule(), screenModules(), platformModule(analytics))
m
Nice, I like the name
platformModule
I'd steal that 😛
r
😀
m
275 Views