https://kotlinlang.org logo
#ios
Title
# ios
r

Rainer Schlonvoigt

11/20/2023, 3:21 PM
Has anybody found a way to pass a
DispatchQueue
from Swift to a kotlin API?
from what i can see Kotlin exposes dispatch queues as
NSObject *
but a
dispatch_queue_t
is actually supposed to be a
NSObject<OS_dispatch_queue>*
and without this extra protocol adherence, the Swift <-> ObjC interop breaks down
so i don’t see any way to pass a Swift
DispatchQueue
a

Andrei Salavei

11/21/2023, 10:16 PM
Hi there! Try this one:
Copy code
// Swift code:
  let queue = DispatchQueue(label: "queue")
  KotlinClassKt.setQueue(queue: queue)

// KotlinClass.kt :
  fun setQueue(queue: dispatch_queue_t) {
    dispatch_async(queue) {
      println("Hello from queue")
    }
  }
2 Views