Hi! Is it possible to use objC library from kotlin...
# ios
m
Hi! Is it possible to use objC library from kotlin/iosMain? I would like to use ZipArchive. Is it possible to call its methods directly from kotlin or do I need a cinterop wrapper? Does cocoapods integration plugin generate the cinterop automatically?
m
yes, you can use cinterop for that: https://kotlinlang.org/docs/native-c-interop.html here is a example: https://kotlinlang.org/docs/native-c-interop.html#filter-headers-by-module-maps you can download the .framework and create kotlin bindings for it using the cinterop tool https://gist.github.com/Ribesg/95a172ceb2177d74cf5b15993d40092e
👍 1
m
This is very cool. So one can say kotlin/native is more similar to C/C++ in terms of project config and library ecosystem. I could create kotlin bindings for some C libraries on linux too, right?
m
yes, if you have the header files for that, you can create a .def file to generate kotlin bindings for the libraries
m
Awesome! Thank you. I will need to probably create some projects to fully understand but this looks very promising
m
just remember you have to add the dependency on your iOS project anyway (Swift PM or pod file), because Kotlin Native will only create bindings. I mean the binary of the bound library will not be embedded on the produced kotlin library
👀 2
m
This is important insight. I will keep that in mind 🙌
b
Interesting. This is great.