Title
a

adev_one

04/12/2017, 6:56 PM
There is a way to call kotlin from objective c/swift in iOS?
s

svyatoslav.scherbina

04/12/2017, 7:16 PM
Yes, there are some tricks to achieve this. 1) You can run Kotlin
main
function from C by calling
Konan_main
C function. It can be declared as
extern "C" int Konan_main(int argc, const char** argv);
For example, see
concurrent
sample: https://github.com/JetBrains/kotlin-native/blob/master/samples/concurrent/MessageChannel.cpp#L156 2) You can pass some Kotlin functions as callbacks through C interop. See https://github.com/JetBrains/kotlin-native/blob/master/INTEROP.md#callbacks for more details. Using callbacks is currently not so trivial as it could be. It is required to declare function type (e.g. using
typedef
) in C header and then generate bindings with
cinterop
tool.
a

adev_one

04/14/2017, 7:27 PM
@svyatoslav.scherbina Can I compile my kotlin code to static library (or llvm bytecode) or I should compile whole my project by konanc/kotlinc? I tried to include .kexe just like .a and compile .bc by clang and include but xcode cant build my project with "clang: error: linker command failed with exit code 1".
o

olonho

04/15/2017, 8:49 AM
you use
konanc
as the final linker, linking with external .a, but entry point could be in those .a, not in Kotlin code, see Tetris example for iphone