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.
-
The implementor is required to have an Array of Element (required by Sequence).
Declaration
Swift
var sequence_contents: Array<Element> { get set }
-
subscript(_:
Default implementation) Subscript access is get-only (for safety).
Default Implementation
Returns an indexed element.
Declaration
Swift
subscript(inIndex: Int) -> Element { get }
Parameters
inIndex
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 implementationThis 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()
-
makeIterator()
Extension methodWe just pass the iterator through to the Array.
Declaration
Swift
public func makeIterator() -> Array<Element>.Iterator
Return Value
The Array iterator for our elements.
-
isEmpty
Extension methodReturns true, if yes, we have no bananas.
Declaration
Swift
public var isEmpty: Bool { get }
-
count
Extension methodThe number of elements we have. 1-based. 0 is no elements (isEmpty is true).
Declaration
Swift
public var count: Int { get }