我在Swift项目中使用的是C库,其中一个函数需要UnsafePointer<UnsafePointer<UInt8>?>!
作为输入输出参数,我应该在其中传递数据。但是问题是我的数据类型为UnsafeMutablePointer<UnsafeMutablePointer<UInt8>?>!
。
我的问题是-在Swift 3中将UnsafeMutablePointer
转换为UnsafePointer
的最有效,最简单的方法是什么?这些指针在“书面上”并没有太大不同,与技术环境也没有太大区别,但是我找不到关于该主题的有值(value)的信息。
任何帮助,将不胜感激。谢谢
最佳答案
UnsafePointers can be initialized with an UnsafeMutablePointer
// Any UnsafeMutablePointer with capacity one
let ump = UnsafeMutablePointer<Any>.allocate(capacity: 1)
// `up` now contains an UnsafePointer initialized with `ump`
var up = UnsafePointer(ump)
关于swift - 将UnsafeMutablePointer转换为UnsafePointer,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48915124/