RVS_SequenceProtocol

public protocol RVS_SequenceProtocol : Sequence

If you conform to this protocol, you get a few basic Sequence attributes for free.

You’ll need to set up a sequence_contents Array (read/write), and set the Element type, and that’s about all.

This also gives you a read-only subscript.

This cannot be applied to enums, as it requires a stored property.

  • subscript(_:) Default implementation

    Subscript access is get-only (for safety).

    Default Implementation

    Returns an indexed element.

    Declaration

    Swift

    subscript(inIndex: Int) -> Element { get }

    Parameters

    index

    The 0-based index to subscript. Must be less than count.

  • Declaration

    Swift

    init(sequence_contents: [Element])

    Parameters

    sequence_contents

    An Array of the element type, to initialize the value.

  • removeAll() Default implementation

    This allows us to remove all the elements in the sequence. It is a mutating function/method.

    Default Implementation

    Default implementation should do fine for us.

    Declaration

    Swift

    mutating func removeAll()

Default Implementation (Optional) Methods and Computed Properties

  • isEmpty Extension method

    Returns true, if yes, we have no bananas.

    Declaration

    Swift

    public var isEmpty: Bool { get }
  • count Extension method

    The number of elements we have. 1-based. 0 is no elements (isEmpty is true).

    Declaration

    Swift

    public var count: Int { get }