Reputation: 353
I would like to get all the keys of an CGPDFDictionaryRef. so far this what I found from stackoverflow
Here is my code in swift:
func printPDFKeys(key: UnsafePointer<Int8>, ob: CGPDFObjectRef, info: UnsafeMutablePointer<()>) -> Void{
NSLog("key = %s", key);
//return (key, ob , info)
}
This function is then called like this.
let myDoc = CGPDFDocumentCreateWithURL(url)
if myDoc != nil {
let myCatalog=CGPDFDocumentGetCatalog(myDoc)
CGPDFDictionaryApplyFunction(myCatalog, printPDFKeys, nil);//Compiler error here
}
However I am getting an error that
a c function pointer can only be formed from a reference to a 'func' or a literal closure
I have also tried using a Closure like this:
var printPDFKeys: ( UnsafePointer<Int8>, CGPDFObjectRef, UnsafeMutablePointer<()> )-> Void
printPDFKeys={
key,ob,info in
NSLog("key = %s", key);
}
I am still getting the same error. How could I go about it
Upvotes: 0
Views: 1172
Reputation: 413
the correct closure syntax would be:
CGPDFDictionaryApplyFunction(myCatalog, { (key, object, info) -> Void in
// do something
}, nil)
Upvotes: 1