我正在尝试将以下代码从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 */)
})
答案 0 :(得分:1)
错误消息:
withUnsafePointers不可用:使用嵌套的withUnsafePointer代替
意味着替换对withUnsafePointers的调用(它需要两个项并创建指向每个项的指针),两个调用withUnsafePointer
,一个调用另一个调整,每个调用一个项目并创建一个指针。
所以这个:
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
}
}
答案 1 :(得分:0)
我在刚刚更新到swift3的项目中使用了linphone。这是我更新这些行的内容。似乎运作良好。希望这有帮助!
var lct: LinphoneCoreVTable = LinphoneCoreVTable()
theLinphoneCore = withUnsafePointer(to: &lct) { (ptr: UnsafePointer<LinphoneCoreVTable>) -> OpaquePointer in
let selfPtr: BTVoipService = self
let voidPtr: UnsafeMutableRawPointer = unsafeBitCast(selfPtr, to: UnsafeMutableRawPointer.self)
return linphone_core_new_with_config (ptr, self.configDb!, voidPtr /* user_data */)
}