Kotlin Native Adds Objective-C Interop, WebAssembly Support

| by Sergio De Simone Follow 18 Followers on Nov 28, 2017. Estimated reading time: 1 minute |

Kotlin/Native 0.4 makes it possible to build native apps for iOS and macOS, writes Nikolay Igotti, Kotlin/Native tech lead at JetBrains. Additionally, it introduces experimental support for the WebAssembly platform.

Objective-C interoperability is the key to Kotlin/Native supporting iOS/macOS development. JetBrains has gone so far as publishing a very simple demo app written in Kotlin both on the Apple Store and Google Play.

This snippet shows how you can access iOS frameworks:

import kotlinx.cinterop.*
import platform.Foundation.*
import platform.objc.*
import platform.osx.*

fun readResource(resourceName: String): ByteArray {
    val filePath = NSBundle.mainBundle.pathForResource(resourceName, ofType = null)
  val fileData = NSData.dataWithContentsOfFile(filePath!!)
  ?: throw Error("failed reading resource $resourceName")
  return fileData.bytes!!.readBytes(fileData.length.toInt())

The magic is provided here by the new platform. libraries, which enable access to underlying operating system interfaces. This makes it also possible to use the POSIX OS layer on a platform that provides it, e.g., to call fopen, fread, and so on. Previously, interoperability with the underlying platform would require the explicit generation of interop stubs.

Another new feature, aimed to simplify the use of Kotlin objects with C API, is object pinning, which can be used to ensure an object is locked in memory when consumed from C APIs.

Kotlin/Native now supports WebAssembly, which means Kotlin can be used for browser-based apps. Support is only experimental, due to browser support limitations, says Igotti.

On the tooling front, debugging now supports inspection on most variables at runtime. And, last but not least, a new plugin provides support for Kotlin/Native in CLion.

Kotlin/Native is a recent development in Kotlin that allows to compile Kotlin, originally a JVM-based language, to native binaries that run without any VM. This makes it especially suitable for platforms such as iOS and embedded targets, where VMs are not allowed or desirable. Kotlin/Native currently supports Windows, Linux, macOS, iOS, Android, and WebAssembly.

Rate this Article

Adoption Stage

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread


Login to InfoQ to interact with what matters most to you.

Recover your password...


Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.


More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.


Stay up-to-date

Set up your notifications and don't miss out on content that matters to you