Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert UnsafeMutablePointer to UnsafePointer

I'm using a C library in my Swift project, and one of functions requires a UnsafePointer<UnsafePointer<UInt8>?>! as an in-out argument where I should pass my data. But the problem is that I have this data in UnsafeMutablePointer<UnsafeMutablePointer<UInt8>?>! type.

My question is - What is the most efficient and easiest way to convert UnsafeMutablePointer to UnsafePointer in Swift 3? Those pointers are not much different "on paper" and they shouldn't be much different from technical context, but I couldn't find valuable information on that topic.

Any help would be appreciated. Thanks

like image 954
Eugene Alexeev Avatar asked Feb 21 '18 20:02

Eugene Alexeev


1 Answers

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)
like image 146
Boris Avatar answered Oct 19 '22 12:10

Boris