https://kotlinlang.org logo
Title
j

J-Rojas

04/04/2018, 4:13 AM
I found more objective-c Foundation library conversions in the K/N runtime. https://github.com/JetBrains/kotlin-native/blob/0bfa68cf037fc6d6141f22cb6e9b9390e989f64d/runtime/src/main/cpp/ObjCExportCollections.mm Could we have these exposed as part of some interop API?
s

Sam

04/04/2018, 4:52 AM
I'm not positive but that looks like the mechanism that allows toll free bridging between Kotlin collections and ObjC collections. One of the sample iOS apps has some interop functions for going from an ObjC collection (array, set, enumerator) to a Kotlin list. It's not a great solution right now though.
j

J-Rojas

04/04/2018, 6:10 AM
Yes, this is part of the toll free bridging layer. But I need to go in the other direction... Kotlin to ObjC. The low level functions C functions appear to be there. But they don't appear to be exposed as a Kotlin module. https://github.com/JetBrains/kotlin-native/blob/0bfa68cf037fc6d6141f22cb6e9b9390e989f64d/runtime/src/main/kotlin/konan/internal/ObjCExportUtils.kt
s

svyatoslav.scherbina

04/04/2018, 6:51 AM
Right now we are working on unifying interoperability between Kotlin and Objective-C in both directions. After this work is done conversion between Kotlin and Objective-C collections will be supposed to become easier (or even automatic). The code you’ve found is related to conversion between Kotlin and Objective-C collections, but it is not suitable when calling from Kotlin to Objective-C yet.
j

J-Rojas

04/04/2018, 8:48 PM
Thanks, the interop would be very helpful. I noticed some checkins related to this in the code recently. Will this be released as part of v1.2.50?
s

svyatoslav.scherbina

04/05/2018, 6:48 AM
We are planning to include this to the next Kotlin/Native release, v0.7.
j

J-Rojas

04/05/2018, 7:30 AM
Great news thanks.
s

svyatoslav.scherbina

04/16/2018, 6:51 AM
In latest dev builds (e.g.
0.7-dev-1587
), Objective-C collections are mapped to Kotlin when importing Objective-C APIs. Also Kotlin
as
cast can be used to convert between equivalent Kotlin and Objective-C types explicitly, e.g.
val kotlinList = nsArray as List<*>
val nsDictionary = kotlinMap as NSDictionary
👏 1