a

    Abhishek Dewan

    1 year ago
    I am trying to write a simple POC where I try to inject an implementation of an interface into iOS and Android. I have the koin dependency defined like shown. In android I can inject using the way I shown below and in iOS I am using the way I have shown below but the iOS one fails and the error it throws is not very useful to determine what’s going on. The Koin.get extension functions that are provided in Kampkit are present in my project as well. Anyone have an idea on how I can achieve this?
    Also koin for iOS is properly defined. The line that injects Kermit works without a problem, not sure what’s wrong with the interface I wrote
    How would one try to get an instance of an interface in this case AuthenticationApi using koin in iOS if anyone has an idea
    Figured out this issue and posting for reference. The KampKit example writes the Koin.get extension functions to expect a ObjC class to be passed into it. However KMP converts interface to a protocol in objc and hence we need to write Koin.get to expect a objc protocol and then use that to deliver the dependency.
    fun Koin.get(objCProtocol: ObjCProtocol): Any {
        val kClazz = getOriginalKotlinClass(objCProtocol)!!
        return get(kClazz)
    }
    and you can get the dependency like
    koin.get(objCProtocol: AuthenticationApi.self) as! AuthenticationApi