如何在 Swift 中为 `dispatch_async_f` 声明 `dispatch_function_t`?
How to declare `dispatch_function_t` for `dispatch_async_f` in Swift?
Xcode 7 beta 5。我正在尝试使用 dispatch_async_f
来避免阻塞。
func myFirstFunc() {
let identifier = QOS_CLASS_BACKGROUND
let queue = dispatch_get_global_queue(identifier, 0)
let context: UnsafeMutablePointer<Void> = nil
let work: dispatch_function_t = myOtherFunc
dispatch_async_f(queue, context, work)
}
func myOtherFunc(context: UnsafeMutablePointer<Void>) {
}
出现错误:
A C function pointer can only be formed from a reference to a 'func'
or a literal closure
看起来myOtherFunc
是一个class的方法,对吧?这仅在 myOtherFunc
被声明为顶层的自由函数时才有效。
Xcode 7 beta 5。我正在尝试使用 dispatch_async_f
来避免阻塞。
func myFirstFunc() {
let identifier = QOS_CLASS_BACKGROUND
let queue = dispatch_get_global_queue(identifier, 0)
let context: UnsafeMutablePointer<Void> = nil
let work: dispatch_function_t = myOtherFunc
dispatch_async_f(queue, context, work)
}
func myOtherFunc(context: UnsafeMutablePointer<Void>) {
}
出现错误:
A C function pointer can only be formed from a reference to a 'func' or a literal closure
看起来myOtherFunc
是一个class的方法,对吧?这仅在 myOtherFunc
被声明为顶层的自由函数时才有效。