Kotlin Native introduces Objective-C interoperability and WebAssembly support

Source: Internet
Author: User

Kotlin Native introduces Objective-C interoperability and WebAssembly support

According to JetBrains Technical Director Nikolay Igotti, Kotlin/Native 0.4 can be used to develop Native applications for iOS and macOS. This version also provides experimental support for the WebAssembly platform.

Kotlin/Native supports iOS/macOS development. The key lies in implementing interoperability with Objective-C. JetBrains has released a very simple demo application, which is written in Kotlin and released to Apple Store and Google Play.

The following code snippet shows how to access the iOS framework:

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())}

All of this is through the newplatformAnd access to the underlying operating system interfaces through the library. This allows you to use a platform that provides the posix OS layer to perform various operations, such as callingfopen,fread. Previously, Interop Stub was specially generated for interoperability with the underlying platform.

Another new feature of the new version, Object pinning, aims to simplify the use of Kotlin objects through the c api, so that the objects consumed through the c api can be locked into the memory.

Kotlin/Native now supports WebAssembly, so you can use Kotlin to develop browser-based applications. However, according to Igotti, due to browser support limitations, such support is still experimental.

In terms of tools, debugging now supports checking most variables at runtime. In addition, it is also important to use a new plug-in to allow CLion to support Kotlin/Native.

Kotlin/Native is the latest achievement of Kotlin and can be used to compile Kotlin, a JVM-based language, as a Native library that can run without a virtual machine. Therefore, this technology is suitable for environments that cannot or cannot run virtual machines, such as iOS platforms and embedded devices. Kotlin/Native currently supports Windows, Linux, macOS, iOS, Android, and WebAssembly.

Kotlin Native Adds Objective-C Interop, WebAssembly Support

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.