Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extension RawRepresentable where RawValue: Numeric {
- /// Returns all the values of a RawRepresentable whose RawValue is Numeric. This static property expressly exists
- /// for enumerations, though can be used elsewhere. Works only for contiguous values.
- /// Supposing we have:
- /// ```
- /// enum Counter {
- /// case one, two
- /// }
- /// ```
- /// then `Counter.allValues == [.one, .two]`.
- static var allValues: [Self] {
- var i: RawValue = 0
- return Array(AnyIterator {
- let result = self.init(rawValue: i)
- i += 1
- return result
- })
- }
- }
Add Comment
Please, Sign In to add comment