-
-
Save riteshhgupta/672a58b5187fbbd4681bb452becf5384 to your computer and use it in GitHub Desktop.
This file contains 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 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
You could also do this for everything that's Hashable.
See https://github.com/evermeer/Stuff/blob/master/Source/Enum/Enum.swift#L54
And for an explanation: https://github.com/evermeer/Stuff#enum