corbella83 / PopKorn

DI can be simple. Forget about modules and components. Just use it!
Apache License 2.0
155 stars 5 forks source link

[SOLVED] iOS: Could not find Provider for this class. Did you forget to add @Injectable? #25

Open gchristov opened 3 years ago

gchristov commented 3 years ago

I'm following the setup instructions but running into an issue trying to inject a dependency on iOS in a kotlin multiplatform project. I have:

fun getInjector() = InjectorObjC(popKorn())

- created a sample file `PopKoIos.kt` in my common source set:

@Injectable class PopKoIos { fun te() = println("TE") }

- initialized PopKorn from `AppDelegate`:

BridgeKt.doInit { (clazz) -> PopkornMapping in return clazz.alloc() as! PopkornMapping }

- injected into my swift file:

let injector = BridgeKt.getInjector() let helloWorld = injector.inject(clazz: PopKoIos.self) as! PopKoIos <- THIS FAILS helloWorld.te()



I am linking my KMM module using the following command `./gradlew :kmm-core:embedAndSignAppleFrameworkForXcode` but I don't see `kapt` running in the logs as with Android.

Am I missing something?
gchristov commented 3 years ago

Turns out I had to do this in my iOS setup, which makes sense as iOS doesn't have access to the generated code by default I believe. Might be worth updating the docs on the README page in case this continues to be maintained 👍

val iosMain by getting {
    ...
    kotlin.srcDir("${buildDir.absolutePath}/generated/source/kaptKotlin/")
}