Skip to content

Instantly share code, notes, and snippets.

@ainoya
Created July 13, 2015 06:14
Show Gist options
  • Save ainoya/5e59a7be712bea07193d to your computer and use it in GitHub Desktop.
Save ainoya/5e59a7be712bea07193d to your computer and use it in GitHub Desktop.
Iterate the values of Enum type with Swift1.2
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