3

Xcode 7 beta 5. I'm attempting to use dispatch_async_f to avoid a block.

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>) {
}

Got an error:

A C function pointer can only be formed from a reference to a 'func' or a literal closure

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • You obviously could just use block to call `myFirstFunc`, e.g. `dispatch_async(queue) { self.myOtherFunc() }`. – Rob Aug 11 '15 at 04:21
  • I thought I could easily avoid a block. Apparently it is not that easy. – Cœur Aug 11 '15 at 05:30

1 Answers1

8

It looks like myOtherFunc is a method of a class, is that right? This will only work if myOtherFunc is declared as a free function at the top level.

Nate Cook
  • 92,417
  • 32
  • 217
  • 178
  • 1
    Oh, can't use class methods? So sad. Then I guess it's better to use a block if I want a background use of `self`. – Cœur Aug 11 '15 at 05:24