Enum with String and Int

in #swift7 years ago
enum Group: String {
  case Me
  case You
  case Her
  case Him
  
  init?(index: Int) {
    switch index {
    case 0: self = .Me
    case 1: self = .You
    case 2: self = .Her
    case 3: self = .Him
    default: return nil
    }
  }
}

print(Group(index: 0)?.rawValue) // Optional("Me")
Sort:  

Congratulations @kwakbab! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 1 year!

Click here to view your Board

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @kwakbab! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!