title: Dealing with the delay due to async communication in AlamoFire
body: <p>I understand that AlamoFire and URL communications with a cloud database is async. My question is how do most people handle the couple second delay of communications.  My app stores the users email address and a bool value of true if they are logged in. If true it jumps to the second viewcontroller with detailed info.  Because of the delay there is no info.  I put a 2 second delay but it looks kludgy on the transitions from view one to two.  Attached is the code. I'm also thinking a wait screen but not sure.  Any help would be great.  Thanks.</p>
  
  <pre><code>var defaultValue:UserDefaults!
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
      defaultValue = UserDefaults.standard
      if let emailUD = defaultValue.object(forKey: "loginEmail") as? String{
          textEmail.text = emailUD
          print("Stored email -", emailUD)
      }
      if let loggedin = defaultValue.object(forKey: "isLoggedIn") as? Bool{
          if loggedin != true{
                  let parameters1: Parameters=[
                      "email":"perry.aten@mymail.com",
                      "password":passwordIn
                  ]
                  Alamofire.request(URL_USER_LOGIN, method: .get, parameters: parameters1).responseJSON
                      { response1 in
                          if response1.result.value != nil{
                              let guardianJSON = JSON(response1.result.value!)
                              let guardian:String = guardianJSON[0]["guardian"].string!
                              print(guardian)
                              print(guardianJSON)
  
                              let league:String = guardianJSON[0]["league"].string!
                              let parameters2: Parameters=[
                                  "league":league
                              ]
                              //Getting League name
                              Alamofire.request(URL_LEAGUE, method: .get, parameters: parameters2).responseJSON
                                  { response2 in
                                      if response2.result.value != nil {
                                          let leagueJSON = JSON(response2.result.value!)
                                          leagueName=leagueJSON[0]["name"].string!
                                          print(leagueJSON)
                                      }
                              }
                          }
                  }
              DispatchQueue.main.asyncAfter(deadline: .now() + 2.0){
                  let loggedInVC = self.storyboard?.instantiateViewController(withIdentifier: "LoggedInID") as! LoggedINViewController
                  self.present(loggedInVC, animated: false, completion: nil)
                  print("They are logged in viewDidLoad")
              }
          }
      }
  }
  </code></pre>