https://kotlinlang.org logo
#ios
Title
# ios
m

Mikolaj

03/27/2024, 11:52 AM
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

magnumrocha

03/28/2024, 12:35 PM
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

Mikolaj

03/28/2024, 12:42 PM
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

magnumrocha

03/28/2024, 12:44 PM
yes, if you have the header files for that, you can create a .def file to generate kotlin bindings for the libraries
m

Mikolaj

03/28/2024, 12:46 PM
Awesome! Thank you. I will need to probably create some projects to fully understand but this looks very promising
m

magnumrocha

03/28/2024, 12:48 PM
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

Mikolaj

03/28/2024, 12:49 PM
This is important insight. I will keep that in mind 🙌
b

brandonmcansh

04/01/2024, 2:59 AM
Interesting. This is great.
3 Views