I currently don't have a mac with me to experiment...
# ios
a
I currently don't have a mac with me to experiment, and I can't seem to find these answers online. I know that a
List
(written in kotlin) is mapped to an `Array`/`NSArray` in Swift/OC I know that a
MutableList
is mapped to an
NSMutableArray
but it is unclear what an
Array
(written in kotlin) is mapped to in Swift. is it also mapped into a 1.
Array
/`NSArray` 2.
NSMutableArray
3.
KotlinArray
How is a kotlin Array mapped into a C as well?. Also not clear in the documentation
k
https://kotlinlang.org/docs/native-objc-interop.html#mappings that should cover a lot of mappings, though it looks like
Array
isnt in there. I think for the most part I just stick to lists when doing KMM work
l
C methods typically handle arrays as pointers, where you have to get the size separately. This would make it difficult for Kotlin to convert to an Array, which has to have a specified size in Kotlin.
I typically write an extension for different CPointer types
CPointer<Something>.toArray(size: Int)
, but different libraries have different ways of determining size, so this has to be written manually, and is also unsafe, as it relies on the assumption that the size is correct. An incorrect size value can lead to very difficult to debug problems.
I personally wish that there would be a built-in version of the method I mentioned that can more efficiently copy the bytes (or even use immutable collections to just wrap the original C array), but I doubt that JB would provide this because it’s inherently unsafe.
a
I just stick to List...
Its all fine sticking with Lists until you start targeting Javascript as well. That's where it all fails hard