如何转换 UnsafePointer<UnsafeMutablePointer<Float>>?到 UnsafeMutablePointer<UnsafeMutableP
Posted
技术标签:
【中文标题】如何转换 UnsafePointer<UnsafeMutablePointer<Float>>?到 UnsafeMutablePointer<UnsafeMutablePointer<Float>?>!【英文标题】:How can I cast UnsafePointer<UnsafeMutablePointer<Float>>? to UnsafeMutablePointer<UnsafeMutablePointer<Float>?>! 【发布时间】:2018-03-12 07:33:50 【问题描述】:我有一个需要在 Swift 中与之交互的 C API。 其中一个函数将指针数组作为参数,由 Swift 导入为
`UnsafeMutablePointer<UnsafeMutablePointer<Float>?>! `
Swift端对应的输入是AVAudioPCMBuffer.floatChannelData,定义为
UnsafePointer<UnsafeMutablePointer<Float>>?
我无法在两者之间进行投射。 我尝试通过执行以下操作使其可变:
UnsafeMutablePointer<UnsafeMutablePointer<Float>>(AVAudioPCMBuffer.floatChannelData)
那没有用。 Swift 指针类型之间的转换非常令人沮丧。任何帮助将不胜感激。
谢谢
【问题讨论】:
【参考方案1】:var testPtr : UnsafeMutablePointer<UnsafeMutablePointer<Float>?>! = nil
var testPtr2 : UnsafePointer<UnsafeMutablePointer<Float>>? = nil
testPtr = unsafeBitCast( testPtr2, to: UnsafeMutablePointer<UnsafeMutablePointer<Float>?>!.self)
【讨论】:
以上是关于如何转换 UnsafePointer<UnsafeMutablePointer<Float>>?到 UnsafeMutablePointer<UnsafeMutableP的主要内容,如果未能解决你的问题,请参考以下文章
无法将“UnsafePointer<Double>”类型的值转换为预期的参数类型“UnsafePointer<_>”
将 Int 转换为 UnsafePointer<UInt8>