【问题标题】:How to get CGPDFDictionaryRef keys如何获取 CGPDFDictionaryRef 键
【发布时间】:2016-02-23 22:27:33
【问题描述】:

我想获取 CGPDFDictionaryRef 的所有键。到目前为止,这是我发现的 from stackoverflow

这是我的 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);//Compiler error here
     }

但是我得到一个错误

c 函数指针只能由对 'func' 的引用构成 或文字闭包

我也尝试过使用这样的闭包:

var printPDFKeys: (  UnsafePointer<Int8>, CGPDFObjectRef,  UnsafeMutablePointer<()> )-> Void

    printPDFKeys={
        key,ob,info in

    NSLog("key = %s", key);

    }

我仍然遇到同样的错误。我该怎么办呢

【问题讨论】:

  • 您好,我尝试使用您的代码,但它对我不起作用。您能否在此处添加完整的答案,以便对未来的读者有所帮助?

标签: ios objective-c swift pdf dictionary


【解决方案1】:

正确的闭包语法是:

CGPDFDictionaryApplyFunction(myCatalog, { (key, object, info) -> Void in
// do something
}, nil)

【讨论】:

  • 您可以根据问题添加完整的答案吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-03
  • 2021-11-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多