Giraffe Giraffe - 1 year ago 154
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 Source
randomName(rawValue: arc4random_uniform(randomName.name8.rawValue + 1))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download