Hi! I’ve got a large byte array (a bitmap) on Swif...
# multiplatform
p
Hi! I’ve got a large byte array (a bitmap) on Swift side inside UInt8[] array. How do I pass it to Kotlin? I have found this answer on Stack Overflow, but it looks very inefficient - every byte is copied in cycle. Is there a more effective way to transfer the byte array?
b
Hey ! Maybe look at this : https://gist.github.com/noahsark769/61cfb7a8b7231e2069a9dab94cf74a62 I don’t know if it is your use case but if you can create a
Data
or
NSData
object in Swift from your UInt8[] array, you’ll be able to produce a Kotlin
ByteArray
p
Thank you so much, Benoit! That was the right direction. Turned out converting UInt8[] to Data is pretty straightforward. let data = Data(bytes: uint8Array, count: arrayLength)