Last active
September 6, 2016 11:54
-
-
Save nubbel/ef564308ced8ca3e8120f82baaf6c453 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension RawRepresentable where RawValue == Int { | |
static func enumerate() -> Self { | |
return self.init(rawValue: 0)! | |
} | |
static func makeIterator() -> AnyIterator<Self> { | |
var index = 0 | |
return AnyIterator { | |
let value = Self.init(rawValue: index) | |
index += 1 | |
return value | |
} | |
} | |
static var all: [Self] { | |
return [Self](makeIterator()) | |
} | |
} | |
enum Section: Int { | |
case Zero, One, Two, Three | |
} | |
for section in Section.makeIterator() { | |
print(section) | |
} | |
Section.all |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment