https://kotlinlang.org logo
Title
a

aleksey.tomin

10/01/2020, 2:59 PM
How can I convert pointer to NSString to kotlin String? ObjC code:
CFArrayRef interfaces = CNCopySupportedInterfaces();
    CFDictionaryRef networkInfo = CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(interfaces, 0));
    NSString *ssid = CFDictionaryGetValue(networkInfo, @"SSID");
I’ve wrote:
val interfaces = CNCopySupportedInterfaces()
val interface: CFStringRef? = CFArrayGetValueAtIndex(interfaces, i)?.reinterpret()
val networkInfo = CNCopyCurrentNetworkInfo(interface)
val ssIdPtr = CFDictionaryGetValue(networkInfo, kCNNetworkInfoKeySSID)
val ssId = ?????
n

Nikolay Kasyanov

10/01/2020, 3:17 PM
a

aleksey.tomin

10/01/2020, 4:47 PM
Thanks!
val ssId = CFBridgingRelease(ssIdPtr) as String
n

Nikolay Kasyanov

10/02/2020, 8:36 AM
an additional retain may be necessary, though