withUnsafeBytes

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

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

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

Parameters: arg: An instance to temporarily access through a raw buffer pointer. body: A closure that takes a raw buffer pointer to the bytes of arg as its sole argument. If the closure has a return value, it is used as the return value of the withUnsafeBytes(of:_:) function. The buffer pointer argument is valid only for the duration of the closure's execution. Returns: The return value of the body closure, if any.

See Also: withUnsafePointer(to:_:), withUnsafeMutableBytes(of:_:)

Declaration

func withUnsafeBytes<T, Result>(of arg: inout T, _ body: (UnsafeRawBufferPointer) throws -> Result) rethrows -> Result