kwakbab avatar

Enum with String and Int

kwakbab

Published: 01 Feb 2018 › Updated: 01 Feb 2018Enum with String and Int

Enum with String and Int

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")

Leave Enum with String and Int to:

Written by

Read more #swift posts


Best Posts From kwakbab

We have not curated any of kwakbab's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From kwakbab