Vivek Modi
05/04/2022, 2:00 PMfun initKoin(
appDeclaration: KoinAppDeclaration = {}
) = startKoin {
appDeclaration()
modules(cartModule)
}
fun iosKoin() = initKoin() {}
val cartModule = module {
single { httpClient() }
single { KtorCountryApi(get()) }
}
I have KtorCountryApi class
class KtorCountryApi(private val httpClient: HttpClient) : NetworkRoute() {
suspend fun getCountry(): ApiResponse<KtorCountriesResponse> {
/// api call
}
}
I am calling the iosKoin() in my .swift file in ios projectVivek Modi
05/04/2022, 2:01 PMKtorCountryApi
in ios with passing httpClient object?Vivek Modi
05/04/2022, 2:02 PMfunc application(_ application: UIApplication,
willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
KoinKt.iosKoin()
let ktorCountryApi = KtorCountryApi.init(httpClient:<#T##Ktor_client_coreHttpClient#>)
return true
}
Trey
05/04/2022, 2:07 PMVivek Modi
05/04/2022, 2:09 PMVivek Modi
05/04/2022, 2:09 PMKtorCountryApi
in ios side?Trey
05/04/2022, 2:09 PMJohn O'Reilly
05/04/2022, 2:10 PMKtorCountryApi
implement KoinComponent
(example of that in following https://github.com/joreilly/PeopleInSpace/blob/main/common/src/commonMain/kotlin/com/surrus/common/repository/PeopleInSpaceRepository.kt)Vivek Modi
05/04/2022, 2:11 PMJohn O'Reilly
05/04/2022, 2:12 PMKtorCountryApi
instance in iOS code (if, as in my case, you're not really using Koin within iOS code)Vivek Modi
05/04/2022, 2:12 PMJohn O'Reilly
05/04/2022, 2:13 PMby inject()
in this exampleVivek Modi
05/04/2022, 2:13 PM