WritingOptions
- iOS
- 8.0+
- macOS
- 10.10+
- tvOS
- 9.0+
- watchOS
- 2.0+
struct WritingOptions
struct WritingOptions
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 Iterator
struct ReadingOptions
struct SearchOptions
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 Equatable
A type that can be compared for value equality.
protocol ExpressibleByArrayLiteral
A type that can be initialized using an array literal.
protocol OptionSet : RawRepresentable, SetAlgebra
A type that presents a mathematical set interface to a bit set.
protocol RawRepresentable<RawValue>
A type that can be converted to and from an associated raw value.
protocol Sendable
protocol SetAlgebra<Element> : Equatable, ExpressibleByArrayLiteral
A type that provides mathematical set operations.
init(rawValue: UInt)
static let atomic: Data.WritingOptions
An option to write data to an auxiliary file first and then replace the original file with the auxiliary file when the write completes.
static let completeFileProtection: Data.WritingOptions
An option to make the file accessible only while the device is unlocked.
static let completeFileProtectionUnlessOpen: Data.WritingOptions
An option to allow the file to be accessible while the device is unlocked or the file is already open.
static let completeFileProtectionUntilFirstUserAuthentication: Data.WritingOptions
An option to allow the file to be accessible after a user first unlocks the device.
static let fileProtectionMask: Data.WritingOptions
An option the system uses when determining the file protection options that the system assigns to the data.
static let noFileProtection: Data.WritingOptions
An option to not encrypt the file when writing it out.
static let withoutOverwriting: Data.WritingOptions
An option that attempts to write data to a file and fails with an error if the destination file already exists.
let rawValue: UInt
init()
Creates an empty option set.
init<S>(_ sequence: S) where S : Sequence, Self.Element == S.Element
Creates a new set from a finite sequence of items.
init(arrayLiteral: Self.Element...)
Creates a set containing the elements of the given array literal.
var isEmpty: Bool { get }
A Boolean value that indicates whether the set has no elements.
static func != (lhs: Self, rhs: Self) -> Bool
Returns a Boolean value indicating whether two values are not equal.
func contains(_ member: Self) -> Bool
Returns a Boolean value that indicates whether a given element is a member of the option set.
mutating func formIntersection(_ other: Self)
Removes all elements of this option set that are not also present in the given set.
mutating func formSymmetricDifference(_ other: Self)
Replaces this set with a new set containing all elements contained in either this set or the given set, but not in both.
mutating func formUnion(_ other: Self)
Inserts the elements of another set into this option set.
@discardableResult mutating func insert(_ newMember: Self.Element) -> (inserted: Bool, memberAfterInsert: Self.Element)
Adds the given element to the option set if it is not already a member.
func intersection(_ other: Self) -> Self
Returns a new option set with only the elements contained in both this set and the given set.
func isDisjoint(with other: Self) -> Bool
Returns a Boolean value that indicates whether the set has no members in common with the given set.
func isStrictSubset(of other: Self) -> Bool
Returns a Boolean value that indicates whether this set is a strict subset of the given set.
func isStrictSuperset(of other: Self) -> Bool
Returns a Boolean value that indicates whether this set is a strict superset of the given set.
func isSubset(of other: Self) -> Bool
Returns a Boolean value that indicates whether the set is a subset of another set.
func isSuperset(of other: Self) -> Bool
Returns a Boolean value that indicates whether the set is a superset of the given set.
@discardableResult mutating func remove(_ member: Self.Element) -> Self.Element?
Removes the given element and all elements subsumed by it.
mutating func subtract(_ other: Self)
Removes the elements of the given set from this set.
func subtracting(_ other: Self) -> Self
Returns a new set containing the elements of this set that do not occur in the given set.
func symmetricDifference(_ other: Self) -> Self
Returns a new option set with the elements contained in this set or in the given set, but not in both.
func union(_ other: Self) -> Self
Returns a new option set of the elements contained in this set, in the given set, or in both.
@discardableResult mutating func update(with newMember: Self.Element) -> Self.Element?
Inserts the given element into the set.