Skip to content

Instantly share code, notes, and snippets.

@EricRabil
Created April 27, 2022 16:29
Show Gist options
  • Save EricRabil/10ad56fb02315c751fe32c8f2f7f4500 to your computer and use it in GitHub Desktop.
Save EricRabil/10ad56fb02315c751fe32c8f2f7f4500 to your computer and use it in GitHub Desktop.
Get current dispatch queue in Swift
extension DispatchQueue {
private static let dispatch_get_current_queue = dlsym(dlopen(nil, RTLD_GLOBAL), "dispatch_get_current_queue")
static var current: DispatchQueue {
dispatch_get_current_queue.map {
unsafeBitCast($0, to: (@convention(c) () -> Unmanaged<DispatchQueue>).self)().takeUnretainedValue()
} ?? .global(qos: .background)
}
}
@huaiguang00
Copy link

It works, Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment