title: Returning values URLSession.shared.dataTask in swift
body: <p>I just started coding in <code>Swift</code> and I have the following code which parses JSON </p>
  
  <pre><code>func parse (latitude: Double, longtitude: Double){
  
  
      let jsonUrlString = "https://api.darksky.net/forecast/apiKey/\(latitude),\(longtitude)"
  
      guard let url = URL(string: jsonUrlString) else{
          return
      }
  
      var information: forecast?
      URLSession.shared.dataTask(with: url) { (data, res, err) in
  
          guard let data = data else { 
                return
          }
  
          do {
              let json = try JSONDecoder().decode(forecast.self, from: data)
              self.info = json
  
          } catch {
              print("didnt work")
          }
  
      }.resume()
  
      processJson(info)
  }
  </code></pre>
  
  <p>My problem is that I want to pass data that is stored in JSON to a variable in the class to be processed using <code>processJson</code> function but since the dataTask function does not return any values, and JSON variable is locally stored I cannot process info variable outside the class (it always returns nil). I was wondering what is the solution to this problem? I'm facing the same problem with <code>weather.getCoordinate()</code>.</p>