title: How to get an array from URLSession
body: <p>Trying to make a program for a news site. I take information from the site through the api, everything works fine.</p>
  
  <p>The only question is, how do I get this array out of the loop?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>import UIKit
  
  class ViewController: UIViewController {
      var news:[News] = []
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          getUsers()            
          print(news)     
      }
  
      func getUsers() {
          guard let url = URL(string: "http://prostir.news/swift/api2.php") else         {return}
          URLSession.shared.dataTask(with: url) { data, response, error in
              if let data = data {
                  do {
                      news = try JSONDecoder().decode([News].self, from: data)
                      // print(self.news)
                  } catch let error {
                      print(error)
                  }
              }
          }.resume()
      }
  }
  </code></pre>