From 85572d7fb2d4ac6377ca518d7b4e8c85ae239e75 Mon Sep 17 00:00:00 2001 From: dankito Date: Thu, 23 Jul 2020 13:18:13 +0200 Subject: [PATCH] Added toByteArray() --- fints4k/src/iosMain/kotlin/Extensions.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/fints4k/src/iosMain/kotlin/Extensions.kt b/fints4k/src/iosMain/kotlin/Extensions.kt index d93c8f7b..80b93417 100644 --- a/fints4k/src/iosMain/kotlin/Extensions.kt +++ b/fints4k/src/iosMain/kotlin/Extensions.kt @@ -1,6 +1,4 @@ -import kotlinx.cinterop.addressOf -import kotlinx.cinterop.convert -import kotlinx.cinterop.usePinned +import kotlinx.cinterop.* import platform.Foundation.* @@ -13,4 +11,10 @@ fun ByteArray.toNSData(): NSData = NSMutableData().apply { this@toNSData.usePinned { appendBytes(it.addressOf(0), size.convert()) } +} + +fun NSData.toByteArray(): ByteArray { + val data: CPointer = bytes!!.reinterpret() + + return ByteArray(length.toInt()) { index -> data[index] } } \ No newline at end of file