title: How to check if function finished?
body: <p>I have a function that requests data from an API and puts it in a global struct, so I can read that data from anywhere in the application, all other functions and classes are mainly working in this data. I want to check if that function has finished loading the data before running the other class functions.</p>
  
  <p>The other functions are in different classes. </p>
  
  <p>I cannot use a completion handler (completion: @escaping(_ success: Bool) -> Void) . as this will trigger that function every time it's called, thus it will lead to the data being downloaded over and over again.</p>
  
  <p>Instead, I'm looking for a way to check if that function has completed it's download tasks, then continue with the other functions.</p>
  
  <p>This has to be dynamic, since if let's say, the internet on the device was not working, and then the user connects to the internet, that function will need to run again to try to get the data (could use a refresh button) and notify other classes and function that it finished again so the other functions can start loading the data into the variables</p>
  
  <pre><code>import Foundation 
  import Alamofire 
  import SwiftyJSON
  
  struct GlobalUser {
      static var json : JSON!
       }
  
  
  func getData()  {
  
      // set api url
      let LOCATIONAPI_URL = "https://api.darksky.net/forecast/0123456789abcdef9876543210fedcba/42.3601,-71.0589"
  
      // request JSON from url, using Alamofire Library
  
      Alamofire.request(LOCATIONAPI_URL).responseJSON { (response) in
  
          print("data requested")
  
          let result = response.result
  
  
          // check if respose is valid
  
          if result.isSuccess{
  
           GlobalUser.json = JSON(result.value!)    
  
       }
  
  }
  
  }
  </code></pre>