Calls the given closure with a pointer to the array’s mutable contiguous storage.
- Xcode 7.0+
- Swift Standard Library
A closure with an
Unsafeparameter that points to the contiguous storage for the array. If no such storage exists, it is created. If
Mutable Buffer Pointer
bodyhas a return value, it is used as the return value for the
withmethod. The pointer argument is valid only for the duration of the method’s execution.
Unsafe Mutable Buffer Pointer(_:)
The return value of the
body closure parameter, if any.
Often, the optimizer can eliminate bounds checks within an array algorithm, but when that fails, invoking the same algorithm on the buffer pointer passed into your closure lets you trade safety for speed.
The following example shows how modifying the contents of the
Unsafe argument to
body alters the contents of the array:
The pointer passed as an argument to
body is valid only during the execution of
with. Do not store or return the pointer for later use.