Created
July 13, 2015 06:14
-
-
Save ainoya/5e59a7be712bea07193d to your computer and use it in GitHub Desktop.
Iterate the values of Enum type with Swift1.2
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
enum SoundEffectType:Int { | |
case Whitsle = 0, | |
Finish, | |
CDThree, | |
CDTwo, | |
CDOne, | |
CDGo, | |
Good, | |
Great, | |
Excellent, | |
Fantastic, | |
Marvelous, | |
Poor, | |
OK, | |
HighScore, | |
LevelUp | |
class EnumGenerator:GeneratorType { | |
var i = 0 | |
typealias Element = SoundEffectType | |
func next() -> Element? { | |
let r = SoundEffectType(rawValue: i) | |
i += 1 | |
return r | |
} | |
} | |
static func enumerate() -> SequenceOf<SoundEffectType> { | |
return SequenceOf<SoundEffectType>({ EnumGenerator() }) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment