I found more objective-c Foundation library conver...
# kotlin-native
j
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
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
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
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
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
We are planning to include this to the next Kotlin/Native release, v0.7.
j
Great news thanks.
s
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.
Copy code
val kotlinList = nsArray as List<*>
val nsDictionary = kotlinMap as NSDictionary
👏 1