Hello team, I am having some issue with injecting ...
# multiplatform
c
Hello team, I am having some issue with injecting dependencies into IOS side with KOIN.
Copy code
class DependenciesProviderHelper {

    companion object {
        lateinit var koin: Koin
    }

    fun initKoinWithPlatformModules(
        config: KoinAppDeclaration? = null,
        platformModules: List<Module> = emptyList()
    ) {
        val instance = startKoin {
            config?.invoke(this)
            analytics()
            modules(
                listOf(
                    ComposeAppModule().module,
                    CoreDataModule().module,
                    CorePresentationModule().module,
                    OnboardingPresentationModule().module,
                    StorePresentationModule().module
                ) + platformModules
            )
        }

        koin = instance.koin
    }
}

@OptIn(BetaInteropApi::class)
fun Koin.get(objCClass: ObjCClass): Any {
    val kClazz = getOriginalKotlinClass(objCClass)!!
    return get(kClazz, null, null)
}

@OptIn(BetaInteropApi::class)
fun Koin.get(objCClass: ObjCClass, qualifier: Qualifier?, parameter: Any): Any {
    val kClazz = getOriginalKotlinClass(objCClass)!!
    return get(kClazz, qualifier) { parametersOf(parameter) }
}
In IOS Side AppDelegate.application()
Copy code
DependenciesProviderHelper().doInitKoinWithPlatformModules(
            config: nil, platformModules : [analyticsModule]
        )
        
        Task {
            let featureFlagManager: FeatureFlagManager = get()
        }
DiHelper.swift
Copy code
func get<A: AnyObject>() -> A {
    return DependenciesProviderHelper.companion.koin.get(objCClass: A.self) as! A
}

func get<A: AnyObject>(_ type: A.Type) -> A {
    return DependenciesProviderHelper.companion.koin.get(objCClass: A.self) as! A
}

func get<A: AnyObject>(_ type: A.Type, qualifier: (any Koin_coreQualifier)? = nil, parameter: Any) -> A {
    return DependenciesProviderHelper.companion.koin.get(objCClass: A.self, qualifier: qualifier, parameter: parameter) as! A
}
I get error
Task 1: EXC_BAD_ACCESS (code=1, address=0x310)
on
get()
What might be the issue?
f
can you try this approach? it’s simpler
c
I was having issues with SKIE earlier, let me try this
f
SKIE is not mandatory for using koin injection
c
🥹 Nope I was not able to get this working.
c
#C67HDJZ2N Please don't cross post. It spams the channels and risks losing context for other people when they search for related problems in the future.
c
Hii @Ciaran Sloan, Yes I understand but it was also related to type conversion from kotlin to objc/swift so it felt correct to include it here too.
c
Post a link for reference rather than create two different threads.
c
Got it, will keep it in mind from now on