Data
A byte buffer in memory.
Declaration
@frozen struct DataMentioned in
Overview
The Data value type allows simple byte buffers to take on the behavior of Foundation objects. You can create empty or pre-populated buffers from a variety of sources and later add or remove bytes. You can filter and sort the content, or compare against other buffers. You can manipulate subranges of bytes and iterate over some or all of them.
Data bridges to the NSData class and its mutable subclass, NSMutableData. You can use these interchangeably in code that interacts with Objective-C APIs.
Topics
Creating Empty Data
Creating Populated Data
init()init(buffer:)init(buffer:)init(bytes:count:)init(bytesNoCopy:count:deallocator:)init(capacity:)init(count:)
Creating Data from Raw Memory
Reading and Writing Data
Base-64 Encoding
base64EncodedData(options:)base64EncodedString(options:)Data.Base64DecodingOptionsData.Base64EncodingOptions
Accessing Bytes
Accessing Underlying Memory
withUnsafeBytes(_:)withUnsafeMutableBytes(_:)copyBytes(to:count:)copyBytes(to:from:)copyBytes(to:from:)
Adding Bytes
Replacing a Range of Bytes
replaceSubrange(_:with:)replaceSubrange(_:with:)replaceSubrange(_:with:)replaceSubrange(_:with:count:)
Finding Bytes
Excluding Bytes
Iterating Over Bytes
Splitting the Buffer
Comparing Data
Manipulating Indexes
Describing Data
Using Reference Types
Initializers
init(base64Encoded:options:)init(base64Encoded:options:)init(bytes:)init(bytes:)init(bytes:)init(contentsOf:options:)init(referencing:)init(repeating:count:)