我想要一个CGPDFDictionaryRef的所有密钥。到目前为止这是我发现的from stackoverflow
这是我的代码在斯威夫特:
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);//Compiler error here
}但是我得到了一个错误
C函数指针只能由对“func”或文字闭包的引用形成。
我也尝试过使用这样的闭包:
var printPDFKeys: ( UnsafePointer<Int8>, CGPDFObjectRef, UnsafeMutablePointer<()> )-> Void
printPDFKeys={
key,ob,info in
NSLog("key = %s", key);
}我还是会犯同样的错误。我该怎么做呢?
发布于 2016-02-23 23:20:23
正确的闭包语法是:
CGPDFDictionaryApplyFunction(myCatalog, { (key, object, info) -> Void in
// do something
}, nil)https://stackoverflow.com/questions/35589516
复制相似问题