I am trying to parse PDF files and I've nearly got the code working. The only thing I can't seem to figure out is to translate the following Objective C code, into Swift. I need to call my own written function to register it as a callback.
The Objective-C code is:
CGPDFOperatorTableSetCallback(operatorTable, "q", &op_q);
and the function is
static void op_q(CGPDFScannerRef s, void *info) {
// Do whatever you have to do in here
// info is whatever you passed to CGPDFScannerCreate
}
What would the Swift equivalents be?
You don't need to create your own
op_qfunction to use as a function pointer if you don't want to. Use Swift's closure syntax:Here
("q" as NSString).UTF8Stringgives you anUsafePointer<Int8>which acts as aconst char *bridged to Swift from C.If you wanted to use a function pointer, it might look like this: