Example code:
let context = ["ABC", "XYZ", nil]
How to convert this array to type UnsafeMutableRawPointer?
CodePudding user response:
You can withUnsafeMutablePointer
to get a typed unsafe pointer and then create a raw version if you need it untyped:
var context = ["ABC", "XYZ", nil]
withUnsafeMutablePointer(to: &context) { p in
let rawPointer = UnsafeMutableRawPointer(p)
print(rawPointer)
}
Of course, beware of the memory issues that come along with using any of the 'unsafe' Swift features.