withUnsafeMutableBytes(_:)
Calls the given closure with a mutable pointer to the underlying bytes of the viewed contiguous storage.
Declaration
mutating func withUnsafeMutableBytes<E, Result>(_ body: (UnsafeMutableRawBufferPointer) throws(E) -> Result) throws(E) -> Result where E : Error, Result : ~CopyableParameters
- body:
A closure with an
UnsafeMutableRawBufferPointerparameter that points to the viewed contiguous storage. Ifbodyhas a return value, that value is also used as the return value for thewithUnsafeMutableBytes(_:)method. The closure’s parameter is valid only for the duration of its execution.
Return Value
The return value of the body closure parameter.
Discussion
The buffer pointer passed as an argument to body is valid only during the execution of withUnsafeMutableBytes(_:). Do not store or return the pointer for later use.