How to convert an UnsafeMutablePointer to a Data object

811 Views Asked by At

How do you convert an UnsafeMutablePointer to a Data object?

let bytes = UnsafeMutablePointer<UInt8>.allocate(capacity: 20)
let data: Data = ...?
1

There are 1 best solutions below

3
Rob On BEST ANSWER

You can use:

let data = Data(bytes: bytes, count: 20)