Hi Do you know how to call this function from iOS ...
# ktor
t
Hi Do you know how to call this function from iOS code ?
Copy code
fun ContentType.Companion.fromFilePath(path: String): List<ContentType>
https://api.ktor.io/ktor-http/io.ktor.http/from-file-path.html I tried various ways without success,
Copy code
Ktor_httpContentType.Companion.shared.fromFilePath
c
My first guess would be
Ktor_httpContentType.shared.fromFilePath
?
also ensure that the ktor dependency is exported on ios
m
I think that you need to find a better way to do this so you don't need to call this Ktor function from iOS, instead just pass the path from iOS to Kotlin shared module then call the Ktor function there.
1
t
"`Ktor_httpContentType.shared.fromFilePath` " is what I tried. It does not work. > also ensure that the ktor dependency is exported on ios I have access to
Ktor_httpContentType.companion.parse(value:)
so I don't know what else to do @Ciaran Sloan
@mohamed rejeb Thanks. That's what I already did. My question was more to know what I got wrong and why it's not possible to access an Extension function on a Companion object from a library
c
you can access
parse
because its a declared in the companion object of the class. (See screenshot)
however the function you are trying to execute is an extension function on the companion object, declared in a different file
so you'd need to do something like
FileContentTypeKt.ContentType.shared.fromFilePath("")
. Not entirely sure about this, but I'd imagine this is more the direction you'd need to go
m
Yes I think that it's not possible to use Extension Function from Swift but you can create a function in your common code and use it in swift as a workaround.
Copy code
fun contentTypeFromFilePath(path: String): List<ContentType> = ContentType.fromFilePath(path)
t
I tried it as well, but it did not find
FileContentTypeKt
@Ciaran Sloan
As I said @mohamed rejeb that's what I already did. Thanks for your help. It was more out of curiosity that I wanted to see if it's not possible from Swift
m
Ah ok, But why you are exporting Ktor to iOS, try to avoid this as much as possible because it will increase the iOS app size.
c
yeah, I agree. I tend to avoid exposing the internals of kotlin and its libraries to the platforms and instead just write interfaces that allows the platforms to interact with the underlying implementation
1
t
Thanks for your help 🙏 We are progressively migrating our iOS codebase to integrate KMP parts so we have interactions at various layers that's why Ktor is exported I'll keep in mind the potential optimisation 👍
👍🏼 1