Skip to content

Instance Method

withUnsafeBytes(_:)

iOS 8.0+ iPadOS 8.0+ Mac Catalyst 8.0+ macOS 10.10+ tvOS 9.0+ watchOS 2.0+
Calls the given closure with the contents of underlying storage.
func withUnsafeBytes<R>(_ body: (UnsafeRawBufferPointer) throws -> R) rethrows -> R

Discussion

Note

Calling withUnsafeBytes multiple times does not guarantee that the same buffer pointer will be passed in every time.

Warning

The buffer argument to the body should not be stored or used outside of the lifetime of the call to the closure.

Clients should prefer the withBytes function to this one, because withBytes uses the non-escapable type RawSpan to ensure that the buffer argument is not stored outside of the closure.