CaseIterable

public extension CaseIterable where Self: Equatable

Extension adds a circular iterator to a CaseIterable item, usually an enum

   enum MyEnum: CaseIterable { case a, b, c }
   var letter = MyEnum.a
   letter.toNext(true)  // .b
   letter.toNext(true)  // .c
   letter.toNext(true)  // .a
   letter.toNext(true)  // .b
   letter.toNext(false)  // .a
   letter.toNext(false)  // .c

Available where Self: Equatable

  • Returns the next enumerated value (circularly)

    Declaration

    Swift

    var next: Self { get }
  • Returns the previous enumerated value (circularly)

    Declaration

    Swift

    var prev: Self { get }
  • Increments or decrements self (circularly)

    Declaration

    Swift

    @available(*, deprecated, message: "use .toNext(next:﹚ instead")
    mutating func next(_ next: Bool = true)
  • Increments or decrements self (circularly)

    Declaration

    Swift

    mutating func toNext(_ next: Bool)
  • Increments or decrements self (circular)

    Declaration

    Swift

    @available(*, deprecated, message: "use .toNext(next:﹚ instead")
    mutating func increment(next: Bool)
  • Returns an incremented or decremented copy of self (circular)

    Declaration

    Swift

    @available(*, deprecated, message: "use properties .next or .prev instead")
    mutating func incremented(next: Bool) -> Self