Generic Structure

UnsafeBufferPointer

A non-owning collection interface to a buffer of elements stored contiguously in memory.

Overview

You can use an UnsafeBufferPointer instance in low level operations to eliminate uniqueness checks and, in release mode, bounds checks. Bounds checks are always performed in debug mode.

UnsafeBufferPointer Semantics

An UnsafeBufferPointer instance is a view into memory and does not own the memory that it references. Copying a value of type UnsafeBufferPointer does not copy the instances stored in the underlying memory. However, initializing another collection with an UnsafeBufferPointer instance copies the instances out of the referenced memory and into the new collection.

Topics

Related Types

struct UnsafeBufferPointerIterator

An iterator for the elements in the buffer referenced by an UnsafeBufferPointer or UnsafeMutableBufferPointer instance.

Initializers

init(rebasing: RandomAccessSlice<UnsafeBufferPointer<Element>>)

Creates a buffer over the same memory as the given buffer slice.

Beta
init(rebasing: MutableRandomAccessSlice<UnsafeMutableBufferPointer<Element>>)

Creates a buffer over the same memory as the given buffer slice.

Beta
init(start: UnsafePointer<Element>?, count: Int)

Creates a new buffer pointer over the specified number of contiguous instances beginning at the given pointer.

Instance Properties

var baseAddress: UnsafePointer<Element>?

A pointer to the first element of the buffer.

var count: Int

The number of elements in the buffer.

Beta
var count: Int

The number of elements in the collection.

Beta
var debugDescription: String

A textual representation of the buffer, suitable for debugging.

var endIndex: Int

The “past the end” position—that is, the position one greater than the last valid subscript argument.

var first: Element?

The first element of the collection.

var indices: DefaultRandomAccessIndices<UnsafeBufferPointer<Element>>

The indices that are valid for subscripting the collection, in ascending order.

var indices: CountableRange<Int>

The indices that are valid for subscripting the collection, in ascending order.

var isEmpty: Bool

A Boolean value indicating whether the collection is empty.

var last: Element?

The last element of the collection.

var lazy: LazyCollection<UnsafeBufferPointer<Element>>

A view onto this collection that provides lazy implementations of normally eager operations, such as map and filter.

var lazy: LazySequence<UnsafeBufferPointer<Element>>

A sequence containing the same elements as this sequence, but on which some operations, such as map and filter, are implemented lazily.

var lazy: LazyRandomAccessCollection<UnsafeBufferPointer<Element>>

A view onto this collection that provides lazy implementations of normally eager operations, such as map and filter.

var lazy: LazyBidirectionalCollection<UnsafeBufferPointer<Element>>

A view onto this collection that provides lazy implementations of normally eager operations, such as map and filter.

var startIndex: Int

The index of the first element in a nonempty buffer.

var underestimatedCount: Int

A value less than or equal to the number of elements in the collection.

Beta
var underestimatedCount: Int

Returns a value less than or equal to the number of elements in the sequence, nondestructively.

Beta

Instance Methods

func contains(where: (Element) -> Bool)

Returns a Boolean value indicating whether the sequence contains an element that satisfies the given predicate.

func drop(while: (Element) -> Bool)

Returns a subsequence by skipping elements while predicate returns true and returning the remaining elements.

func dropFirst()

Returns a subsequence containing all but the first element of the sequence.

func dropFirst(Int)

Returns a subsequence containing all but the given number of initial elements.

func dropLast()

Returns a subsequence containing all but the last element of the sequence.

func dropLast(Int)

Returns a subsequence containing all but the specified number of final elements.

func elementsEqual<OtherSequence>(OtherSequence)

Returns a Boolean value indicating whether this sequence and another sequence contain the same elements in the same order.

func elementsEqual<OtherSequence>(OtherSequence, by: (Element, Element) -> Bool)

Returns a Boolean value indicating whether this sequence and another sequence contain equivalent elements, using the given predicate as the equivalence test.

func enumerated()

Returns a sequence of pairs (n, x), where n represents a consecutive integer starting at zero, and x represents an element of the sequence.

func filter((Element) -> Bool)

Returns an array containing, in order, the elements of the sequence that satisfy the given predicate.

func first(where: (Element) -> Bool)

Returns the first element of the sequence that satisfies the given predicate.

func forEach((Element) -> Void)

Calls the given closure on each element in the sequence in the same order as a for-in loop.

func index(of: Element)

Returns the first index where the specified value appears in the collection.

func index(where: (Element) -> Bool)

Returns the first index in which an element of the collection satisfies the given predicate.

func joined()

Returns the elements of this collection of collections, concatenated.

Beta
func joined()

Returns the elements of this sequence of sequences, concatenated.

Beta
func joined()

Returns the elements of this collection of collections, concatenated.

Beta
func joined<Separator>(separator: Separator)

Returns the concatenated elements of this sequence of sequences, inserting the given separator between each element.

func joined(separator: String)

Returns a new string by concatenating the elements of the sequence, adding the given separator between each element.

func joined(separator: String)

Returns a new string by concatenating the elements of the sequence, adding the given separator between each element.

Beta
func lexicographicallyPrecedes<OtherSequence>(OtherSequence)

Returns a Boolean value indicating whether the sequence precedes another sequence in a lexicographical (dictionary) ordering, using the less-than operator (<) to compare elements.

func lexicographicallyPrecedes<OtherSequence>(OtherSequence, by: (Element, Element) -> Bool)

Returns a Boolean value indicating whether the sequence precedes another sequence in a lexicographical (dictionary) ordering, using the given predicate to compare elements.

func makeIterator()

Returns an iterator over the elements of this buffer.

func map<T>((Element) -> T)

Returns an array containing the results of mapping the given closure over the sequence’s elements.

Beta
func map<T>((Element) -> T)

Returns an array containing the results of mapping the given closure over the sequence’s elements.

Beta
func max()

Returns the maximum element in the sequence.

func max(by: (Element, Element) -> Bool)

Returns the maximum element in the sequence, using the given predicate as the comparison between elements.

func min()

Returns the minimum element in the sequence.

func min(by: (Element, Element) -> Bool)

Returns the minimum element in the sequence, using the given predicate as the comparison between elements.

func prefix(Int)

Returns a subsequence, up to the specified maximum length, containing the initial elements of the collection.

func prefix(through: Int)

Returns a subsequence from the start of the collection through the specified position.

func prefix(upTo: Int)

Returns a subsequence from the start of the collection up to, but not including, the specified position.

func prefix(while: (Element) -> Bool)

Returns a subsequence containing the initial elements until predicate returns false and skipping the remaining elements.

func reduce<Result>(Result, (Result, Element) -> Result)

Returns the result of combining the elements of the sequence using the given closure.

func reversed()

Returns a view presenting the elements of the collection in reverse order.

func sorted()

Returns the elements of the sequence, sorted.

func sorted(by: (Element, Element) -> Bool)

Returns the elements of the sequence, sorted using the given predicate as the comparison between elements.

func split(maxSplits: Int, omittingEmptySubsequences: Bool, whereSeparator: (Element) -> Bool)

Returns the longest possible subsequences of the collection, in order, that don’t contain elements satisfying the given predicate.

func split(separator: Element, maxSplits: Int, omittingEmptySubsequences: Bool)

Returns the longest possible subsequences of the sequence, in order, around elements equal to the given element.

Beta
func split(separator: Element, maxSplits: Int, omittingEmptySubsequences: Bool)

Returns the longest possible subsequences of the collection, in order, around elements equal to the given element.

Beta
func starts<PossiblePrefix>(with: PossiblePrefix)

Returns a Boolean value indicating whether the initial elements of the sequence are the same as the elements in another sequence.

func starts<PossiblePrefix>(with: PossiblePrefix, by: (Element, Element) -> Bool)

Returns a Boolean value indicating whether the initial elements of the sequence are equivalent to the elements in another sequence, using the given predicate as the equivalence test.

func suffix(Int)

Returns a subsequence, up to the given maximum length, containing the final elements of the collection.

func suffix(from: Int)

Returns a subsequence from the specified position to the end of the collection.

Subscripts

subscript(Int)

Accesses the element at the specified position.

subscript(Range<Int>)

Accesses a contiguous subrange of the collection’s elements.

Beta

See Also

Typed Pointers

struct UnsafePointer

A pointer for accessing data of a specific type.

struct UnsafeMutablePointer

A pointer for accessing and manipulating data of a specific type.

struct UnsafeMutableBufferPointer

A non-owning collection interface to a buffer of mutable elements stored contiguously in memory.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software