Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- class Cell {
- var name: String
- init(_ name: String) {
- self.name = name
- }
- }
- class Row: Sequence, IteratorProtocol {
- typealias Element = Cell
- var iteratorIndex: Int = 0
- var cells = [Cell]()
- init(cellNames: String...) {
- for name in cellNames {
- cells.append(Cell(name))
- }
- }
- func next() -> Cell? {
- if iteratorIndex >= cells.count {
- return nil
- }
- defer {
- iteratorIndex += 1
- }
- return cells[iteratorIndex]
- }
- func makeIterator() -> Row {
- self.iteratorIndex = 0
- return self
- }
- }
- let row = Row(cellNames: "one", "two", "three")
- for cell in row {
- print(cell.name)
- }
- for (index, cell) in row.enumerated() {
- print("[\(index), \(cell.name)]")
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement