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

    Types

    • struct Iterator

      An iterator that produces one or zero instances of an element.

    Typealiases

    Type members

    • init(Element)

      Creates an instance containing just the given element.

    Instance members

    Citizens in Swift

    where Element:Copyable, Element:Sendable, Element:Escapable

    Conformances

    Citizens in Swift

    where Element:Copyable, Element:Escapable

    Conformances

    Instance features

    Show obsolete interfaces (2)

    Hide obsolete interfaces

    Available in FoundationEssentials

    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.

    Instance members