title: Why can't we use protocol `Encodable` as a type in the func?
body: <p>I'm trying to get data by encode model which conforms to <code>Encodable</code> protocol. But it's failed to invoke func <code>encode</code> like code below:</p>
  
  <pre><code>// MARK: - Demo2
  
  class TestClass2: NSObject, Encodable {
      var x = 1
      var y = 2
  }
  
  
  var dataSource2: Encodable?
  
  dataSource2 = TestClass2()
  
  // error: `Cannot invoke 'encode' with an argument list of type '(Encodable)'`
  let _ = try JSONEncoder().encode(dataSource2!)
  //func encode&lt;T&gt;(_ value: T) throws -&gt; Data where T : Encodable
  </code></pre>
  
  <p>But in another demo, it works well, why?</p>
  
  <pre><code>// MARK: - Demo1
  
  protocol TestProtocol {
      func test()
  }
  
  class TestClass1: NSObject, TestProtocol {
      func test() {
          print("1")
      }
  
      var x = 1
      var y = 2
  }
  
  
  var dataSource1: TestProtocol?
  
  dataSource1 = TestClass1()
  
  
  func logItem(_ value: TestProtocol) {
      value.test()
  }
  
  logItem(dataSource1!)
  </code></pre>