当我定义行时,我遇到了一个构建错误
let runFont : CTFontRef = CFDictionaryGetValue(CTRunGetAttributes(run), kCTFontAttributeName)
错误是:无法将"CFString"类型的值转换为预期的参数类型"UnsafePointer"(又名"UnsafoPointer<()>')
尝试
let runFont = unsafeBitCast(CFDictionaryGetValue(CTRunGetAttributes(run), unsafeBitCast(kCTFontAttributeName, UnsafePointer<Void>.self)), CTFontRef.self)
Swift 3版本的@vadian答案:
let runFont = unsafeBitCast(CFDictionaryGetValue(CTRunGetAttributes(run), unsafeBitCast(kCTFontAttributeName, to: UnsafeRawPointer.self)), to: CTFont.self)