https://kotlinlang.org logo
#kotlin-native
Title
# kotlin-native
m

magnumrocha

01/05/2021, 6:15 PM
how to correctly call the function:
Copy code
@kotlinx.cinterop.internal.CCall public external fun SCNetworkReachabilityGetFlags(target: platform.SystemConfiguration.SCNetworkReachabilityRef? /* = kotlinx.cinterop.CPointer<cnames.structs.__SCNetworkReachability>? */, flags: kotlinx.cinterop.CValuesRef<platform.SystemConfiguration.SCNetworkReachabilityFlagsVar /* = kotlinx.cinterop.UIntVarOf<kotlin.UInt> */>?): kotlin.Boolean { /* compiled code */ }
to receive the 
kSCNetworkReachabilityFlags…
 correctly? in Swift, we can make the call:
Copy code
var flags: SCNetworkReachabilityFlags = []
if !SCNetworkReachabilityGetFlags(defaultRouteReachability, &flags) {
    return false
}
And receive the flags in an array style…. In Kotlin Native, I am doing:
Copy code
// val flags = allocArray<SCNetworkReachabilityFlagsVar>(10) // -> this was my first attempt, they are 10 possible flags!
val flags = alloc<SCNetworkReachabilityFlagsVar>()

if (!SCNetworkReachabilityGetFlags(reachabilityRef, flags.ptr)) return false
the problem is I am receiving all the flag “summed” (they are 
kotlin.UInt
), and not split in an array, like in Swift.
r

russhwolf

01/05/2021, 8:42 PM
Try
allocArrayOf()
m

magnumrocha

01/06/2021, 10:18 AM
@russhwolf the
allocArrayOf()
needs a
vargarg
as a parameter, how could I use it?
a

Artyom Degtyarev [JB]

01/11/2021, 3:01 PM
Hello, @magnumrocha! I’ve found an example here, thanks to the thread. Please take a look.
👍 1
m

magnumrocha

01/11/2021, 5:20 PM
thanks @Artyom Degtyarev [JB] 👍 I’m using it right this way
12 Views