title: Can't access data outside of closure in swift
body: <p>I am trying to extract an array from closure in swift 3 and its not working for me. I have my JSON parser in the class WeatherGetter and I am calling it in the view did load file in the viewcontroller.swift how to assign the weather_data array to some outside variable?</p>
  
  <pre><code>class WeatherGetter {
  
      func getWeather(_ zip: String, startdate: String, enddate: String, completion: @escaping (([[Double]]) -&gt; Void)) {
          // This is a pretty simple networking task, so the shared session will do.
          let session = URLSession.shared
  
          let string = "Insert API address"
  
          let url = URL(string: string)
          var weatherRequestURL = URLRequest(url:url! as URL)
          weatherRequestURL.httpMethod = "GET"
  
  
          // The data task retrieves the data.
          let dataTask = session.dataTask(with: weatherRequestURL) {
              (data, response, error) -&gt; Void in
              if let error = error {
                  // Case 1: Error
                  // We got some kind of error while trying to get data from the server.
                  print("Error:\n\(error)")
              }
              else {
                  // Case 2: Success
                  // We got a response from the server!
                  do {
                      var temps = [Double]()
                      var winds = [Double]()
                      let weather = try JSON(data: data!)
                      //print(weather)
                      let conditions1 = weather["data"]
                      let conditions2 = conditions1["weather"]
                      let count = conditions2.count
                      for i in 0...count-1 {
                          let conditions3 = conditions2[i]
                          let conditions4 = conditions3["hourly"]
                          let count2 = conditions4.count
                          for j in 0...count2-1 {
                              let conditions5 = conditions4[j]
                              let tempF = conditions5["tempF"].doubleValue
                              let windspeed = conditions5["windspeedKmph"].doubleValue
                              //temps.updateValue(tempF, forKey: "\(date)//\(j)")
                              temps.append(tempF)
                              winds.append(windspeed)
                          }
                      }
                      //print(temps)
                      //print(winds)
                      completion([temps, winds])
  
                  }
                  catch let jsonError as NSError {
                      // An error occurred while trying to convert the data into a Swift dictionary.
                      print("JSON error description: \(jsonError.description)")
                  }
              }
          }
  
          // The data task is set up...launch it!
  
          dataTask.resume()
      }
  
  
  }
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
      let weather = WeatherGetter()
  
      weather.getWeather("13323", startdate: "2016-10-01", enddate: "2017-04-30"){(weather_data) -&gt; Void in
          print(weather_data[1])
      }
  
          //Do your stuff with isResponse variable.
      }
  </code></pre>