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

霸气de小男生 提交于 2019-12-24 00:59:40

问题


I am getting a build error, when I define the line

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

And the error is: Cannot convert value of type 'CFString' to expected argument type 'UnsafePointer' (aka 'UnsafePointer<()>')


回答1:


Try

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



回答2:


Swift 3 version of @vadian answer:

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


来源:https://stackoverflow.com/questions/36310251/cannot-convert-value-of-type-cfstring-to-expected-argument-type-unsafepointer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!