StructureSwift5.9.0

    CollectionOfOne

    A collection containing a single element.

    @frozen struct CollectionOfOne<Element>

    You can use a CollectionOfOne instance when you need to efficiently represent a single value as a collection. For example, you can add a single element to an array by using a CollectionOfOne instance with the concatenation operator (+):

    let a = [1, 2, 3, 4]
    let toAdd = 100
    let b = a + CollectionOfOne(toAdd)
    // b == [1, 2, 3, 4, 100]

    Citizens in Swift

    Conformances

    Members

    Features

    Citizens in Swift

    where Element:Sendable

    Conformances

    • protocol Sendable

      A type whose values can safely be passed across concurrency domains by copying.

    Available in Foundation

    where Element == UInt8

    Conformances

    • protocol ContiguousBytes

      Indicates that the conforming type is a contiguous collection of raw bytes whose underlying storage is directly accessible by withUnsafeBytes.

    Members