![]() You see the text that Swift sends to Kotlin in the wrapper function (in the end, the resulting 'string' variable will be displayed). Let cStr = swiftMessage.cString(using: 8) The changes in ViewController.swift in the function viewDidAppear are: let swiftMessage: String = "Hello Kotlin, this is Swift!" The text may be stupid, but it tells you, what happens. ![]() If you follow along, you should get the following displayed: Since there were some roadblocks in this seemingly simple extension, I lay out the steps for anybody interested. ![]() As a proof of principle, that such a function can be build, I extended the project to not only receive a string from Kotlin, but send one to Kotlin, append it, and send the result back. To transfer data with a data model based on Kotlin, I would like to have a generic function, that can pass data to Kotlin, modify that data, and return the result back to the native iOS code. To get the code to run, I had (after cloning from git) to perform a "git submodule sync" before running "./setup.sh". On the technical level, the project contains a script that compiles the Kotlin, C++, and Kotlin/Native part into a static library, which then can be called from the native iOS project. The call is mediated through a C++ layer, which itself starts the Kotlin runtime, passes the request to a Kotlin function, receives the string from it, and passes it back to the Swift UIViewController, which then displays it. In a Swift UIViewController, it calls a wrapper function that shall receive a string from a Kotlin function. The project pointed me in the right direction, since it shows the essential steps to do so: continuing to use native UI code for iOS. ![]() This allows to have a common code base for the data model based on Kotlin, while e.g. Yes, it is possible in a cross-platform project to transfer data between Kotlin and native iOS UI Code by using Kotlin/Native. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |