Swift 4: Parse to generic type using URLSession data task needs to implement Encodable : <p>I have two classes, the first one <code>WebsiteDescription</code> and the second one: <code>Course</code>.</p>

<p>Both have inheritance from <code>Decodable</code> and the first one is implementing the protocol <code>Encoder</code> without no definition.</p>

<p>But, my code has a problem:</p>

<blockquote>
  <p>Type 'WebsiteDescription' does not conform to protocol 'Encodable'</p>
</blockquote>

<p>This error appears in the line:</p>

<p><code>self.requestdata(endpoint: jsonUrlString, type: WebsiteDescription.self) { result, error in
        }</code></p>

<p>The complete code is:</p>

<pre><code>import UIKit

public class WebsiteDescription:Decodable {
    init(){

    }
    let name: String?
    let description: String?
    //let courses: [Course]?

    func encode(to encoder: Encoder) throws {
        do {
        } catch {
            print(error)
        }
    }

}
class Course: Decodable {
    let id: Int?
    let name: String?
    let link: String?
    let imageUrl: String?
}

class RequestController : UIViewController{

    override func viewDidLoad() {
        super.viewDidLoad()
        let jsonUrlString = "http://api.letsbuildthatapp.com/jsondecodable/website_description"

        self.requestdata(endpoint: jsonUrlString, type: WebsiteDescription.self) { result, error in

        }
    }

    func requestdata&lt;T:Codable&gt;(endpoint :String, type: T.Type, completionHandler: @escaping (T?, Error?) -&gt; ()) {

        let jsonUrlString = "http://api.letsbuildthatapp.com/jsondecodable/website_description"
        guard let url = URL(string: jsonUrlString) else {return }
        URLSession.shared.dataTask(with: url){ (data, response, err) in
            guard let data = data else{ completionHandler(nil, nil) }
            do {
                let result = self.parse(data: data, type: type)
                completionHandler(result, nil)
            } catch let jsonErr{
                completionHandler(nil, jsonErr)
            }
        }.resume()
    }

    private func parse&lt;T:Codable&gt;(data: Data,  type: T.Type) -&gt; T? {

        do{
            let json = try JSONDecoder().decode(type, from: data)
            print(json)
            return json
        }catch {
            return nil
        }
        return nil
    }
}
</code></pre>

<p>Well, I'm trying to use <code>URLSession</code> in my method to cast all my request in a single middleware.</p>

<p>How I can resolve the <code>Encodable</code> issue?</p>
