title: Decoding enum in Swift 5 - This CANNOT be this hard
body: <p>I've been trying for the past 3-4 hours to get this stupid thing to decode this enum correctly and now am incredibly frustrated with this! I have a <code>json</code> string returning from an API that looks like this: </p>
  
  <pre><code>[
    {
      "contractType": 0
    }
  ]
  </code></pre>
  
  <p>I am trying to map THAT to an enum called <code>ContractType</code>. This is my whole <code>ContractType</code> enum</p>
  
  <pre><code>enum ContractType: Int {
      case scavenger = 0
  }
  </code></pre>
  
  <p>and this is my extension I tried to make it conform to the <code>Codable</code> protocol.</p>
  
  <pre><code>extension ContractType: Codable {
      enum Key: Int, CodingKey {
          case rawValue
      }
  
      enum CodingError: Error {
          case unknownValue
      }
  
      init(from decoder: Decoder) throws {
          let container = try decoder.container(keyedBy: Key.self)
          let rawValue = try? container.decode(Int.self, forKey: .rawValue)
  
          switch rawValue {
          case 0:
              self = .scavenger
          default:
              throw CodingError.unknownValue
          }
      }
  
      func encode(to encoder: Encoder) throws {
          var container = encoder.container(keyedBy: Key.self)
          switch self {
          case .scavenger:
              try container.encode(0, forKey: .rawValue)
          }
      }
  }
  </code></pre>
  
  <p>What the heck am I doing wrong!? Any help would be greatly appreciated!</p>