https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
a

Archie

03/22/2021, 10:53 AM
Hi guys, I dont know if this is the right channel to ask. but im trying to access
IosClientEngine
inside
iosMain
but I cant seem to find the build function
Ios
? Ive added the dependency
io.ktor:ktor-client-ios:1.5.2
. Is there anything I should do? Does anyone have an example of this. Please help. Thanks in advance.
p

ptsiogas

03/22/2021, 3:44 PM
Hi, you can use an HttpClientProvider and have something like this in your iosMain:
Copy code
@KtorExperimentalAPI
actual class HttpClientProvider {
    actual fun getHttpClient(): HttpClient {
        return HttpClient(Ios) {
            engine {
                //your stuff
            }
        }
    }
}
in your build.gradle.kts you should have something similar to this example:
Copy code
kotlin {
    sourceSets {
        val commonMain by getting {
            dependencies {
                //your stuff
                implementation("io.ktor:ktor-client-core:$ktorVersion")
                implementation("io.ktor:ktor-client-serialization:$ktorVersion")
                implementation("io.ktor:ktor-client-logging:$ktorVersion")
            }
        }

        val iosMain by getting {
            dependencies {
                //your stuff
                implementation("io.ktor:ktor-client-ios:$ktorVersion")
            }
        }
    }
}
I hope this helps you.
a

Archie

03/25/2021, 6:29 AM
@ptsiogas Thanks for the reply. Actually did the exactly same setup as you did here. But apparently, I have to enable commonizer to make it availble in iosMain
Copy code
kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.native.enableDependencyPropagation=false
2 Views