我正在尝试将以下代码从swift 2升级到3,但我发现withUnsafePointers不可用:请改用nesterd withUnsafePointer。我已经尝试了几种方法,但是我做不到。他是我的密码
var v: LinphoneManager = self
var lct: LinphoneCoreVTable = LinphoneCoreVTable()
let theLinphoneCore : OpaquePointer = withUnsafePointers(&lct, &v, { (ptr: UnsafePointer<LinphoneCoreVTable>, selfPtr: UnsafePointer<LinphoneManager>) -> OpaquePointer in
let voidPtr: UnsafeMutableRawPointer = unsafeBitCast(selfPtr, to: UnsafeMutableRawPointer.self)
return linphone_core_new_with_config (ptr, self.configDb!, voidPtr /* user_data */)
})
最佳答案
错误信息:
withUnsafePointers不可用:改用嵌套的withUnsafePointer
表示用对withUnsafePointer
的两次调用替换对withUnsafePointers的调用(该过程需要两个项目并创建指向每个项目的指针),另一个对ojit_code的调用在另一个闭包内,每个都接受一个项目并创建一个指向它的指针。
所以这:
withUnsafePointers(&a, &b) { aPtr, bPtr in
// do something with aPtr and bPtr
}
变成这个:
withUnsafePointer(&a) { aPtr in
withUnsafePointer(&b) { bPtr in
// do something with aPtr and bPtr
}
}