I am trying to use AWS SDK in KMP. AWS have a Kotl...
# compose-ios
a
I am trying to use AWS SDK in KMP. AWS have a Kotlin SDK for KMP but it is still missing iOS support. Now i am trying to do its implementation via interface. I am wondering if this is a good approach Following are some code snappets: Interface defined in common
Copy code
interface AuthInterface {
    fun signIn(): String
}
implementing that interface in iOS app in iOS module
Copy code
class AWSCognito: AuthInterface{
    
     func signIn() -> String {
         return "Success"
    }  
}
Create the class in App and passing as an interface
Copy code
@main
struct iOSApp: App {
    var awsCognito = AWSCognito()

    var body: some Scene {
       WindowGroup {
            ContentView(auth: awsCognito as AuthInterface)
       }
    }
}
Is this the correct approach or is there any other alternative? I was also wondering about
DI
, is it possible in KOIN ?
m
It is correct approach, in the KMP docs Jetbrains writes something like „if you own the entrance point, you can use it instead of expect/actual“ (expect/actual is quite limited tbh.) And yes, you can use koin. Basically you pass ios implementations of your interfaces into the doKoinInit call; and in commonIOS code where you define the initKoin method, you would construct a new
module {
single <interface> (passedRealIOSImpl)
}
I can send some code tomorrow. Or you can just follow normal koin KMP tutorial on the official website.
c
i continue to be perplexed on when to use expect/actual lol
m
Tbh, i removed all expect/actual in my app, since it’s so limited. Proper DI solves everything, is more powerful and less prone to future api changes imo. It’s kind of easier expect/actual, yes, if you don’t want to touch swift. But in 2024 with chatgpt and copilot, a Kotlin dev can do Swift as well 😂
a
Got it, thanks @Max, i have gone through the docs but never looked at this.