Skip to content

Instantly share code, notes, and snippets.

@Arcovv
Forked from riteshhgupta/swift-snippet-11.swift
Last active March 21, 2017 13:52
Show Gist options
  • Save Arcovv/fd49b114357a87ef42c954a7bd6ddd75 to your computer and use it in GitHub Desktop.
Save Arcovv/fd49b114357a87ef42c954a7bd6ddd75 to your computer and use it in GitHub Desktop.
extension RawRepresentable where RawValue == Int {
static var itemsCount: Int {
var index = 0
while Self(rawValue: index) != nil { index += 1 }
return index
}
static var items: [Self] {
var items: [Self] = []
var index = 0
while let item = Self(rawValue: index) {
items.append(item)
index += 1
}
return items
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment