Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gchristov opened this issue Sep 24, 2021 · 1 comment

Comments

@gchristov
Copy link

gchristov commented Sep 24, 2021

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:

  • added the Bridge.kt file in my iOS source set with the following contents:
fun init(creator: (ObjCClass) -> Mapping) = setup(creator)

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 gchristov changed the title Could not find Provider for this class. Did you forget to add @Injectable? iOS: Could not find Provider for this class. Did you forget to add @Injectable? Sep 24, 2021
@gchristov gchristov changed the title iOS: Could not find Provider for this class. Did you forget to add @Injectable? [SOLVED] iOS: Could not find Provider for this class. Did you forget to add @Injectable? Sep 28, 2021
@gchristov
Copy link
Author

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/")
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant