A C function pointer cannot be formed from a closure that captures context

Viewed 6706

The question is different because I want to take out info value out of the closure. And right now, it's empty thus I couldn't call any outside function. This is what I have tried so far:

CGPDFOperatorTableSetCallback(operatorTableRef!, "BT") { (scanner, info) in
    if let info = info {
        let myObject = Unmanaged<ViewController>.fromOpaque(info).takeUnretainedValue()
        myObject.printinfo(info: info as AnyObject)
}
    }

func printinfo(info:AnyObject) -> Void {
    print("Printing:\n\(info)")
    print("------------------------------------------------------------")
}

I am playing with a PDF to extract strings from it. There's one call block that I should implement. All well, except I can't call any outside function or can't use any variable within that block.

    CGPDFOperatorTableSetCallback(operatorTableRef!, "BT") { (scanner, info) in
        //I can't do anything here except this:
        print("Yes, I can print.")
        //hello() //or self.hello() //all cries.
}

func hello()->Void {
    //hello.
}
0 Answers
Related