如何获取CGPDFDictionaryRef键 [英] How to get CGPDFDictionaryRef keys
本文介绍了如何获取CGPDFDictionaryRef键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里我的代码是swift:
func printPDFKeys(key:UnsafePointer< Int8>,ob:CGPDFObjectRef,info:UnsafeMutablePointer& >) - > Void {
NSLog(key =%s,key);
// return(key,ob,info)
}
然后被称为这样。
let myDoc = CGPDFDocumentCreateWithURL(url)
if myDoc!= nil {
let myCatalog = CGPDFDocumentGetCatalog myDoc)
CGPDFDictionaryApplyFunction(myCatalog,printPDFKeys,nil); //这里的编译器错误
}
但是我收到一个错误,
ac函数指针只能从引用 func'
或文字关闭
我也尝试过使用这样的Closure:
var printPDFKeys:(UnsafePointer< Int8>,CGPDFObjectRef,UnsafeMutablePointer()) - > Void
printPDFKeys = {
key,ob,info in
NSLog(key =%s,key);
}
我仍然收到同样的错误。我该怎么办?
解决方案
正确的关闭语法将是:
CGPDFDictionaryApplyFunction(myCatalog,{(key,object,info) - > Void in
// do something
},nil)
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
解决方案
the correct closure syntax would be:
CGPDFDictionaryApplyFunction(myCatalog, { (key, object, info) -> Void in
// do something
}, nil)
这篇关于如何获取CGPDFDictionaryRef键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文