title: Initialize a placeholder empty variable of generic type
body: <p>I'm new to Swift.<br />
  My ultimate goal is to return the value <code>level</code> (which contains decoded JSON) but I am struggling with returning data from my function.</p>
  <p>This is my code:</p>
  <pre class="lang-swift prettyprint-override"><code>func decode&lt;T: Decodable&gt;(_ type: T.Type, from file: String) -&gt; T {
          let decoder = JSONDecoder()
          let urlString = &quot;https://drive.google.com/u/0/uc?id=1WMjoHM2iaKjfx9wZhE_6jmKlcMi_OzGT&amp;export=download&quot;
          var level = type;
          self.loadJson(fromURLString: urlString) { (result) in
              switch result {
              case .success(let data):
                  level = try! decoder.decode(T.self, from: data)
              case .failure(let error):
                  print(error)
              }
          }
  
          return level
      }
  </code></pre>
  <h2>Current problem</h2>
  <p>The current problem is when I try to assign a value to level I get the following error <code>Cannot assign value of type 'T' to type 'T.Type'</code></p>
  <h2>What I've tried</h2>
  <p>My assumption is the error is happening because initializing a variable with T.type is trying to initialize with the name of the Class instead of the Class itself.  I tried to call <code>type.self</code> with no luck.</p>
  <p>I also tried to get creative to not have to initialize an empty variable.  I tried returning <code>decoder.decode(T.self, from: data)</code> but I was getting a weird <code>Unexpected non-void return value in void function</code> error.  I have no idea what that is all about.</p>
  <p>Is there an easy way to initialize an empty variable to return data later when given T.Type</p>