One Logo Pool Ball
Foundation · IOS API REFERENCE

DataProtocol

protocol · iOS 8.0+ · SDK 27.1

protocol DataProtocol : RandomAccessCollection where Self.Element == UInt8, Self.SubSequence : DataProtocol

A protocol that provides consistent data access to the bytes underlying contiguous and noncontiguous data buffers.

Members (4)

method · iOS 8.0+

copyBytes

Swift declaration
@discardableResult func copyBytes<DestinationType>(to ptr: UnsafeMutableBufferPointer<DestinationType>, count: Int) -> Int

Copies the provided number of bytes from the start of the type into a typed memory buffer. - Parameters: - ptr: A typed pointer to the buffer you want to copy the bytes into. - count: The number of bytes to copy. - Returns: The number of bytes copied.

method · iOS 8.0+

copyBytes

Swift declaration
@discardableResult func copyBytes(to ptr: UnsafeMutableRawBufferPointer, count: Int) -> Int

Copies the provided number of bytes from the start of the type into a raw memory buffer. The following example copies the number of bytes that `count` identified from the beginning of the raw memory buffer into the provided raw memory buffer: ```swift let source: [UInt8] = [0, 1, 2] var dest: [UInt8] = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF] dest.withUnsafeMutableBytes { destBufferPtr in let count = source.copyBytes(to: destBufferPtr, count: 2) // count == 2 } // dest = [0x00, 0x01, 0xFF, 0xFF, 0xFF, 0xFF] ``` - Parameters: - ptr: A pointer to the raw memory buffer you want to copy the bytes into. - count: The number of bytes to copy. - Returns: The number of bytes copied.

method · iOS 8.0+

copyBytes

Swift declaration
@discardableResult func copyBytes<DestinationType>(to ptr: UnsafeMutableBufferPointer<DestinationType>) -> Int

Copies the bytes of data from the type into a typed memory buffer. The following example copies the bytes from a typed memory buffer into the provided typed memory buffer: ```swift let source: [UInt8] = [0, 1, 2] var dest: [UInt8] = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF] dest.withUnsafeMutableBufferPointer { typedMemBuffer in let count = source.copyBytes(to: typedMemBuffer) // count == 3 } // dest = [0x00, 0x01, 0x02, 0xFF, 0xFF, 0xFF] ``` - Parameter ptr: A typed pointer to the buffer you want to copy the bytes into. - Returns: The number of bytes copied.

method · iOS 8.0+

copyBytes

Swift declaration
@discardableResult func copyBytes(to ptr: UnsafeMutableRawBufferPointer) -> Int

Copies the bytes of data from the type into a raw memory buffer. The following example copies the bytes from the raw memory buffer into the provided raw memory buffer: ```swift let source: [UInt8] = [0, 1, 2] var dest: [UInt8] = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF] dest.withUnsafeMutableBytes { destBufferPtr in let count = source.copyBytes(to: destBufferPtr) // count == 3 } // dest = [0x00, 0x01, 0x02, 0xFF, 0xFF, 0xFF] ``` - Parameter ptr: A pointer to the raw memory buffer you want to copy the bytes into. - Returns: The number of bytes copied.

Skipped declarations

7 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.

DataProtocol.firstRange(of:)

The iOS SDK compiler rejected this binding: cannot access associated type 'Index' from 'DataProtocol'; use a concrete type or generic parameter base instead

DataProtocol.lastRange(of:)

The iOS SDK compiler rejected this binding: cannot access associated type 'Index' from 'DataProtocol'; use a concrete type or generic parameter base instead

DataProtocol.copyBytes(to:from:)

This declaration needs Swift generic type arguments. (no canonical witness for R)

DataProtocol.copyBytes(to:from:)

This declaration needs Swift generic type arguments. (no canonical witness for R)

DataProtocol.firstRange(of:in:)

This declaration needs Swift generic type arguments. (no canonical witness for R)

DataProtocol.lastRange(of:in:)

This declaration needs Swift generic type arguments. (no canonical witness for R)

DataProtocol.copyBytes(to:from:)

This declaration needs Swift generic type arguments. (no canonical witness for R)

All Foundation types →