Iterator
- iOS
- 8.0+
- macOS
- 10.10+
- tvOS
- 9.0+
- watchOS
- 2.0+
struct Iterator
struct Iterator
import FoundationEssentials
@frozen struct Data
init()
Initialize an empty Data
.
init<S>(_ elements: S) where S : Sequence, S.Element == UInt8
init?(base64Encoded base64Data: Data, options: Data.Base64DecodingOptions = [])
Initialize a Data
from a Base-64, UTF-8 encoded Data
.
init?(base64Encoded base64String: String, options: Data.Base64DecodingOptions = [])
Initialize a Data
from a Base-64 encoded String using the given options.
init<SourceType>(buffer: UnsafeBufferPointer<SourceType>)
Initialize a Data
with copied memory content.
init<SourceType>(buffer: UnsafeMutableBufferPointer<SourceType>)
Initialize a Data
with copied memory content.
init(bytes: UnsafeRawPointer, count: Int)
Initialize a Data
with copied memory content.
init(bytesNoCopy bytes: UnsafeMutableRawPointer, count: Int, deallocator: Data.Deallocator)
Initialize a Data
without copying the bytes.
init(capacity: Int)
Initialize a Data
with the specified size.
init(contentsOf url: URL, options: Data.ReadingOptions = []) throws
Initialize a Data
with the contents of a URL
.
init(count: Int)
Initialize a Data
with the specified count of zeroed bytes.
init(from decoder: any Decoder) throws
init(repeating repeatedValue: UInt8, count: Int)
Initialize a Data
with a repeating byte pattern
var count: Int { get set }
The number of bytes in the data.
var customMirror: Mirror { get }
var debugDescription: String { get }
A human-readable debug description for the data.
var description: String { get }
A human-readable description for the data.
var endIndex: Data.Index { get }
The end Index
into the data.
var indices: Range<Int> { get }
var regions: CollectionOfOne<Data> { get }
var startIndex: Data.Index { get }
The start Index
in the data.
subscript(bounds: Range<Data.Index>) -> Data { get set }
subscript<R>(rangeExpression: R) -> Data where R : RangeExpression, R.Bound : FixedWidthInteger { get set }
subscript(index: Data.Index) -> UInt8 { get set }
Sets or returns the byte at the specified index.
static func == (d1: Data, d2: Data) -> Bool
Returns true
if the two Data
arguments are equal.
func advanced(by amount: Int) -> Data
mutating func append(_ other: Data)
mutating func append<SourceType>(_ buffer: UnsafeBufferPointer<SourceType>)
Append a buffer of bytes to the data.
mutating func append(_ bytes: UnsafePointer<UInt8>, count: Int)
mutating func append(contentsOf bytes: [UInt8])
mutating func append<S>(contentsOf elements: S) where S : Sequence, S.Element == UInt8
func base64EncodedData(options: Data.Base64EncodingOptions = []) -> Data
Returns a Base-64 encoded Data
.
func base64EncodedString(options: Data.Base64EncodingOptions = []) -> String
Returns a Base-64 encoded string.
func copyBytes(to pointer: UnsafeMutablePointer<UInt8>, count: Int)
Copy the contents of the data to a pointer.
func copyBytes<DestinationType>(to buffer: UnsafeMutableBufferPointer<DestinationType>, from range: Range<Data.Index>? = nil) -> Int
This function copies the bytes in range
from the data into the buffer. If the count of the range
is greater than MemoryLayout<DestinationType>.stride * buffer.count
then the first N bytes will be copied into the buffer.
func copyBytes(to pointer: UnsafeMutablePointer<UInt8>, from range: Range<Data.Index>)
Copy a subset of the contents of the data to a pointer.
func encode(to encoder: any Encoder) throws
func hash(into hasher: inout Hasher)
The hash value for the data.
func index(after i: Data.Index) -> Data.Index
func index(before i: Data.Index) -> Data.Index
func makeIterator() -> Data.Iterator
An iterator over the contents of the data.
mutating func replaceSubrange(_ subrange: Range<Data.Index>, with data: Data)
Replace a region of bytes in the data with new data.
mutating func replaceSubrange<SourceType>(_ subrange: Range<Data.Index>, with buffer: UnsafeBufferPointer<SourceType>)
Replace a region of bytes in the data with new bytes from a buffer.
mutating func replaceSubrange<ByteCollection>(_ subrange: Range<Data.Index>, with newElements: ByteCollection) where ByteCollection : Collection, ByteCollection.Element == UInt8
Replace a region of bytes in the data with new bytes from a collection.
mutating func replaceSubrange(_ subrange: Range<Data.Index>, with bytes: UnsafeRawPointer, count cnt: Int)
mutating func reserveCapacity(_ minimumCapacity: Int)
mutating func resetBytes(in range: Range<Data.Index>)
Set a region of the data to 0
.
func subdata(in range: Range<Data.Index>) -> Data
Return a new copy of the data in a specified range.
func withContiguousStorageIfAvailable<ResultType>(_ body: (UnsafeBufferPointer<UInt8>) throws -> ResultType) rethrows -> ResultType?
func withUnsafeBytes<ResultType>(_ body: (UnsafeRawBufferPointer) throws -> ResultType) rethrows -> ResultType
mutating func withUnsafeMutableBytes<ResultType>(_ body: (UnsafeMutableRawBufferPointer) throws -> ResultType) rethrows -> ResultType
func write(to url: URL, options: Data.WritingOptions = []) throws
Write the contents of the Data
to a location.
struct Base64DecodingOptions
struct Base64EncodingOptions
enum Deallocator
When creating a Data
with the no-copy initializer, you may specify a Data.Deallocator
to customize the behavior of how the backing store is deallocated.
struct ReadingOptions
struct SearchOptions
struct WritingOptions
typealias Index = Int
typealias Indices = Range<Int>
init(bytes: Array<UInt8>)
init(bytes: ArraySlice<UInt8>)
init<S>(bytes elements: S) where S : Sequence, S.Element == UInt8
func enumerateBytes(_ block: (UnsafeBufferPointer<UInt8>, Data.Index, inout Bool) -> Void)
Enumerate the contents of the data.
func withUnsafeBytes<ResultType, ContentType>(_ body: (UnsafePointer<ContentType>) throws -> ResultType) rethrows -> ResultType
Access the bytes in the data.
mutating func withUnsafeMutableBytes<ResultType, ContentType>(_ body: (UnsafeMutablePointer<ContentType>) throws -> ResultType) rethrows -> ResultType
Mutate the bytes in the data.
protocol IteratorProtocol<Element>
A type that supplies the values of a sequence one at a time.
protocol Sendable
mutating func next() -> UInt8?