CaseCountable.swift 413 B

1234567891011121314151617181920
  1. //
  2. // CaseCountable.swift
  3. // RileyLink
  4. //
  5. // Created by Pete Schwamb on 12/30/16.
  6. // Copyright © 2016 Pete Schwamb. All rights reserved.
  7. //
  8. import Foundation
  9. protocol CaseCountable: RawRepresentable {}
  10. extension CaseCountable where RawValue == Int {
  11. static var count: Int {
  12. var i: Int = 0
  13. while let new = Self(rawValue: i) { i = new.rawValue.advanced(by: 1) }
  14. return i
  15. }
  16. }