【问题标题】:Cannot convert value of type 'CFString' to expected argument type 'UnsafePointer<Void>' (aka 'UnsafePointer<()>')无法将“CFString”类型的值转换为预期的参数类型“UnsafePointer<Void>”(又名“UnsafePointer<()>”)
【发布时间】:2016-07-18 12:58:08
【问题描述】:

我在定义行时遇到构建错误

 let runFont : CTFontRef = CFDictionaryGetValue(CTRunGetAttributes(run), kCTFontAttributeName)

错误是:无法将“CFString”类型的值转换为预期的参数类型“UnsafePointer”(又名“UnsafePointer”)

【问题讨论】:

  • UnsafePointer 错误通常意味着受影响的参数被用作 inout 指针。通过 QuickHelp 阅读文档,⌥-单击或⌘-单击符号或按 ⇧⌘0 并输入方法名称。
  • 嗨@vadian你能不能给我一个如何解决它的代码示例..我查看了文档并尝试了很多方法但不起作用:(

标签: ios swift cocoa core-text quartz-core


【解决方案1】:

试试

let runFont = unsafeBitCast(CFDictionaryGetValue(CTRunGetAttributes(run), unsafeBitCast(kCTFontAttributeName, UnsafePointer<Void>.self)), CTFontRef.self)

【讨论】:

    【解决方案2】:

    Swift 3 版本的@vadian 答案:

    let runFont = unsafeBitCast(CFDictionaryGetValue(CTRunGetAttributes(run), unsafeBitCast(kCTFontAttributeName, to: UnsafeRawPointer.self)), to: CTFont.self)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-18
      • 2021-10-02
      • 2017-01-13
      • 2020-03-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-15
      • 1970-01-01
      相关资源
      最近更新 更多