Giraffe Giraffe - 2 months ago 4
Swift Question

How to randomly select an enum in Swift

enum randomName: UInt32 {
case name1
case name2
case name3
case name4
case name5
case name6
case name7
case name8
}


I want to make a function to randomly pick a name from the enum. How do I do that?

Answer
randomName(rawValue: arc4random_uniform(randomName.name8.rawValue + 1))