Generic Function

withUnsafeMutableBytes(of:_:)

Invokes the given closure with a mutable buffer pointer covering the raw bytes of the given argument.

Declaration

func withUnsafeMutableBytes<T, Result>(of value: inout T, _ body: (UnsafeMutableRawBufferPointer) throws -> Result) rethrows -> Result

Parameters

value

An instance to temporarily access through a mutable raw buffer pointer. Note that the inout exclusivity rules mean that, like any other inout argument, value cannot be directly accessed by other code for the duration of body. Access must only occur through the pointer argument to body until body returns.

body

A closure that takes a raw buffer pointer to the bytes of value as its sole argument. If the closure has a return value, that value is also used as the return value of the withUnsafeMutableBytes(of:_:) function. The buffer pointer argument is valid only for the duration of the closure’s execution.

Return Value

The return value, if any, of the body closure.

Discussion

The buffer pointer argument to the body closure provides a collection interface to the raw bytes of value. The buffer is the size of the instance passed as value and does not include any remote storage.

See Also

Memory Access

func withUnsafePointer<T, Result>(to: T, (UnsafePointer<T>) -> Result) -> Result

Invokes the given closure with a pointer to the given argument.

func withUnsafePointer<T, Result>(to: inout T, (UnsafePointer<T>) -> Result) -> Result

Invokes the given closure with a pointer to the given argument.

func withUnsafeMutablePointer<T, Result>(to: inout T, (UnsafeMutablePointer<T>) -> Result) -> Result

Calls the given closure with a mutable pointer to the given argument.

func withUnsafeBytes<T, Result>(of: T, (UnsafeRawBufferPointer) -> Result) -> Result

Invokes the given closure with a buffer pointer covering the raw bytes of the given argument.

func withUnsafeBytes<T, Result>(of: inout T, (UnsafeRawBufferPointer) -> Result) -> Result

Invokes the given closure with a buffer pointer covering the raw bytes of the given argument.

func swap<T>(inout T, inout T)

Exchanges the values of the two arguments.