Nikolai
04/11/2019, 10:03 AMolonho
04/11/2019, 10:20 AMsvyatoslav.scherbina
04/11/2019, 10:49 AMOr maybe where is a way to convert string to NSString?Sure.
str as NSString
.Nikolai
04/11/2019, 10:54 AMsvyatoslav.scherbina
04/11/2019, 11:05 AMNikolai
04/11/2019, 11:08 AMlouiscad
04/11/2019, 11:42 AMJurriaan Mous
04/11/2019, 11:57 AM/** Object to convert base 64 */
actual object Base64 {
/** Decode [base64] string into bytes array */
actual fun decode(base64: String): ByteArray {
// For this library end padding is mandatory so add possible missing padding
val value = base64.padEnd(
length = ((base64.length + 3) / 4) * 4,
padChar = '='
)
val data = NSData.create(value, 0) ?: throw ParseException("Invalid Base64 value $base64")
@Suppress("UNCHECKED_CAST")
val bytePtr = (data.bytes as CPointer<uint8_tVar>)
return ByteArray(data.length.toInt()) { index ->
bytePtr[index].toByte()
}
}
/** Encode [bytes] array into a base64 String */
actual fun encode(bytes: ByteArray) = memScoped {
NSData.create(
bytesNoCopy = bytes.toCValues().getPointer(this),
length = bytes.size.toULong()
).base64EncodedStringWithOptions(0).dropLastWhile {
// Remove any Base64 padding
it == '='
}
}
}
svyatoslav.scherbina
04/11/2019, 12:49 PMNSString.create(string = str)
.louiscad
04/11/2019, 1:06 PMDima Avdeev
04/11/2019, 2:16 PMRan
02/02/2021, 8:27 AMNSString.create(string = str)
in K/N 1.4.10svyatoslav.scherbina
02/02/2021, 8:33 AMCannot useAccording to your screenshot, you don’t use the named argument (in K/N 1.4.10NSString.create(string = str)
string =
), which is important here.
NSString.create(string = str)
totally works for me.Ran
02/02/2021, 8:34 AM