https://kotlinlang.org logo
Title
k

khairil.ushan

04/30/2018, 3:19 PM
So I'm trying to convert a NSData to NSString, in Obj-C I can do it like this
NSString *newStr = [NSString stringWithUTF8String:[data bytes]];
So i tried that in K/N like this
val newStr = NSString.stringWithUTF8String(data!!.bytes!!)
But I got this error message
Error:(21, 55) type mismatch: inferred type is COpaquePointer? /* = CPointer<out CPointed>? */ but CPointer<ByteVar /* = ByteVarOf<Byte> */>? was expected
So what've I missed here? Thanks. 🙂
s

svyatoslav.scherbina

04/30/2018, 4:11 PM
This message means that
data!!.bytes!!
is
void*
, but
stringWithUTF8String
expects
char*
. You can pass
data!!.bytes!!.reinterpret<ByteVar>()
instead.
k

khairil.ushan

04/30/2018, 4:32 PM
It's work.. Thank you so much. 🙂
Hi @svyatoslav.scherbina since I do this code for Networking purpose, is there any plan to have a HTTP Client library for Kotlin MPP?
s

svyatoslav.scherbina

05/01/2018, 9:06 AM
We plan to make a common Kotlin HTTP client library, but there is no ETA.
k

khairil.ushan

05/01/2018, 11:06 AM
Awesome.