Guest User

Untitled

a guest
Nov 17th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. extension RawRepresentable where RawValue: Numeric {
  2. /// Returns all the values of a RawRepresentable whose RawValue is Numeric. This static property expressly exists
  3. /// for enumerations, though can be used elsewhere. Works only for contiguous values.
  4. /// Supposing we have:
  5. /// ```
  6. /// enum Counter {
  7. /// case one, two
  8. /// }
  9. /// ```
  10. /// then `Counter.allValues == [.one, .two]`.
  11. static var allValues: [Self] {
  12. var i: RawValue = 0
  13. return Array(AnyIterator {
  14. let result = self.init(rawValue: i)
  15. i += 1
  16.  
  17. return result
  18. })
  19. }
  20. }
Add Comment
Please, Sign In to add comment