Skip to content

Instantly share code, notes, and snippets.

@nubbel
Last active September 6, 2016 11:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nubbel/ef564308ced8ca3e8120f82baaf6c453 to your computer and use it in GitHub Desktop.
Save nubbel/ef564308ced8ca3e8120f82baaf6c453 to your computer and use it in GitHub Desktop.
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