Using CFArrayGetValueAtIndex in Swift with UnsafePointer (AUPreset)

拈花ヽ惹草 提交于 2020-01-24 13:50:14

问题


My problem is simple, but tricky. I want to write this line

AUPreset *aPreset = (AUPreset*)CFArrayGetValueAtIndex(mEQPresetsArray, indexPath.row);

in Swift. The trick is that the return value is UnsafePointer<Void>.


回答1:


Have you tried this?:

    let aPreset = UnsafePointer<AUPreset>(CFArrayGetValueAtIndex(mEQPresetsArray, indexPath.row))



回答2:


Here's the Swift 4 version

let aPreset = unsafeBitCast(CFArrayGetValueAtIndex(mEQPresetsArray, indexPath), to: AUPreset.self)


来源:https://stackoverflow.com/questions/38475249/using-cfarraygetvalueatindex-in-swift-with-unsafepointer-aupreset

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