title: How do I make an enum Decodable in Swift?
body: <pre><code>enum PostType: Decodable {
  
      init(from decoder: Decoder) throws {
  
          // What do i put here?
      }
  
      case Image
      enum CodingKeys: String, CodingKey {
          case image
      }
  }
  </code></pre>
  <p>What do i put to complete this?
  Also, lets say i changed the <code>case</code> to this:</p>
  <pre><code>case image(value: Int)
  </code></pre>
  <p>How do I make this conform to Decodable?</p>
  <p>Here is my full code (which does not work)</p>
  <pre><code>let jsonData = &quot;&quot;&quot;
  {
      &quot;count&quot;: 4
  }
  &quot;&quot;&quot;.data(using: .utf8)!
          
          do {
              let decoder = JSONDecoder()
              let response = try decoder.decode(PostType.self, from: jsonData)
              
              print(response)
          } catch {
              print(error)
          }
      }
  }
  
  enum PostType: Int, Codable {
      case count = 4
  }
  </code></pre>
  <p>Also, how will it handle an enum like this?</p>
  <pre><code>enum PostType: Decodable {
      case count(number: Int)
  }
  </code></pre>