title: Loading Codable data from URL
body: <p>I'm building an app to fetch and display data from <a href="https://www.hackingwithswift.com/samples/friendface.json" rel="nofollow noreferrer">https://www.hackingwithswift.com/samples/friendface.json</a>.</p>
  <p>I've created following structs:</p>
  <pre><code>struct Response: Codable {
      var results: [User]
  }
  
  struct User: Codable {
      struct Friend: Codable {
          var id: String
          var name: String
      }
      
      var id: String
      var isActive: Bool
      var name: String
      var age: Int
      var company: String
      var email: String
      var address: String
      var about: String
      var regiestered: Date
      var tags: [String]
      var friends: [Friend]
  }
  
  let urlString = &quot;https://www.hackingwithswift.com/samples/friendface.json&quot;
  </code></pre>
  <p>Then I try loading data using function like this:</p>
  <pre><code>func loadData () {
          guard let url = URL(string: urlString) else {
              print(&quot;Invalid URL&quot;)
              return
          }
          let request = URLRequest(url: url)
          URLSession.shared.dataTask(with: request) { data, response, error in
              if let data = data {
                  if let decodedResponse = try? JSONDecoder().decode(Response.self, from: data) {
                      DispatchQueue.main.async {
                          self.results = decodedResponse.results
                      }
                      return
                  }
              }
              print(&quot;Fetch failed: \(error?.localizedDescription ?? &quot;Unknown error&quot;)&quot;)
          }.resume()
      }
  </code></pre>
  <p>But when running the app I get &quot;Unknown error&quot; output. What am I doing wrong?</p>