diff --git a/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/Extensions.kt b/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/Extensions.kt index 17fbd50b..a514c5a8 100644 --- a/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/Extensions.kt +++ b/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/Extensions.kt @@ -1,7 +1,7 @@ package net.dankito.utils.multiplatform -import platform.Foundation.NSArray -import platform.Foundation.NSDictionary +import kotlinx.cinterop.* +import platform.Foundation.* fun NSArray.toList(): List { @@ -25,4 +25,22 @@ fun NSDictionary.getString(key: String, defaultValue: String): String { fun NSDictionary.getStringOrEmpty(key: String): String { return this.getString(key, "") +} + + +fun String.toNSData(): NSData { + return this.encodeToByteArray().toNSData() +} + +fun ByteArray.toNSData(): NSData = NSMutableData().apply { + if (isEmpty()) return@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 diff --git a/fints4k/src/iosMain/kotlin/Extensions.kt b/fints4k/src/iosMain/kotlin/Extensions.kt deleted file mode 100644 index 80b93417..00000000 --- a/fints4k/src/iosMain/kotlin/Extensions.kt +++ /dev/null @@ -1,20 +0,0 @@ -import kotlinx.cinterop.* -import platform.Foundation.* - - -fun String.toNsData(): NSData { - return this.encodeToByteArray().toNSData() -} - -fun ByteArray.toNSData(): NSData = NSMutableData().apply { - if (isEmpty()) return@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