Converting a UnsafeMutableBufferPointer to UnsafeMutablePointer

I am having a lot of trouble trying to convert an UnsafeMutableBufferPointer to an UnsafeMutablePointer.

Here is the scenario:

The api has two methods:

Method 1:

func fill(array: inout [UInt8]) -> Int {
        // needs to call method 2

Method 2:

func fill(buffer: UnsafeMutablePointer<UInt8>, length: Int) -> Int {

I am having problems converting the swift array in method 1 into a form that can be accepted by method 2.

Here is what I tried:

Method 1:

array.withUnsafeMutableBufferPointer { ptr ->

This makes ptr an UnsafeMutableBufferPointer

However, I cannot seem to convert that pointer to a UnsafeMutablePointer that method 2 requires.

Any ideas?

Use baseAddress Apple Developer Documentation

Terms of Service

Privacy Policy

Cookie Policy