i've been able to compile library for iphone targe...
# kotlin-native
a
i've been able to compile library for iphone target and now i have a stupid question - can i use it inside obj-c or swift project? and how to link it properly?
s
@abatutin Hello. How does your library interface look like? Do you want to call Kotlin from Objective-C/Swift? If so, does your library interface use anything except primitive types and pointers (
CPointer<...>
)?
a
so far i have a simple
Copy code
fun test() {
    println("Hello, World!")
}
code in my lib
and i want to call it form objc/swift
s
Embedding Kotlin Native code as a library is not quite ready yet. You can try to add
main
function to Kotlin Native part, and call your true
main
from it. In this case Objective-C/Swift part should be compiled into static library and supplied to Kotlin compiler through
-linkerOpts
. Then, to call Kotlin function from Objective-C you can either 1) Export the function from Kotlin with internal annotation
@konan.internal.ExportForCppRuntime(<name>)
and import it in Objective-C by declaring it as usual C function, or 2) Pass Kotlin functions to Objective-C as pointers using
staticCFunction
.
The second approach will become simpler due to Objective-C interop.
a
i see, thnx
staticCFunction
worked, thnx
do you know if embedding kotlin as lib to c/objc/swift is going to be a thing?
s
It will be supported, but there is no ETA.
❤️ 4
a
👍