无法将类型 'CFString' 的值转换为预期的参数类型 'UnsafePointer<Void>'(又名 'UnsafePointer<()>')

Cannot convert value of type 'CFString' to expected argument type 'UnsafePointer<Void>' (aka 'UnsafePointer<()>')

当我定义行时出现构建错误

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

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

尝试

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

Swift @vadian 回答的 3 个版本:

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