Creates a data buffer with memory content without copying the bytes.
SDKs
- iOS 7.0+
- macOS 10.9+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
- Xcode 8.0+
Framework
- Foundation
Declaration
init(bytesNoCopy bytes: Unsafe Mutable Raw Pointer, count: Int, deallocator: Data.Deallocator)
Parameters
bytes
A pointer to the bytes.
count
The size of the bytes.
deallocator
Specifies the mechanism to free the indicated buffer, or
.none
.
Discussion
If the result is mutated and is not a unique reference, then the Data
will still follow copy-on-write semantics. In this case, the copy will use its own deallocator. Therefore, it is usually best to only use this initializer when you either enforce immutability with let
or ensure that no other references to the underlying data are formed.