title: Wait for multiple Alamofire Requests to finish
body: <p>I have a below function in my network class which do the Alamofire Request process. I'm calling this function in my model class and when Alamofire finishes the request it calls delegate function which notify model class. My problem is that I'm calling this Alamofire function multiple times and both should finish before notifying model class. Now I handle it with very dummy way. As I searched, DispatchGroup can be used but I can't figure it out, how to implement it. Thank you.</p>
  
  <p>Model Class</p>
  
  <pre><code> @objc func refresh_fiks(){
      let network = Network()
      network.delegate = self
      self.teams = [[]]
      network.getRequest(req: 1)
      network.getRequest(req: 2)
  
  }
  </code></pre>
  
  <p>Request Function:</p>
  
  <pre><code>    func response(){
      print(response_json.count)
      if(response_json.count == path){
          self.delegate?.sendJson(response_json)
      }
      }
      func getRequest(req: Int) {
      path = req
      let rot = Router(method: .get, path: req, parameters: nil)
      Alamofire.request(rot)
          .response { response in
              print(response.request?.url! as Any)
              // check for errors
              guard response.error == nil else {
                  // got an error in getting the data, need to handle it
                  print(response.error!)
                  let errorJson: JSON = [ "Error" : "Can't get the data!"]
                  self.response_json.append(errorJson)
                  self.response()
                  return
              }
              // make sure we got some JSON since that's what we expect
              guard (response.data?.base64EncodedString()) != nil else {
                  print("Error: \(String(describing: response.error))")
                  let errorJson: JSON = [ "Error" : "Can't get the data!"]
                  self.response_json.append(errorJson)
                  self.response()
                  return
              }
              guard response.response?.statusCode == 200 else{
                  let errorJson: JSON = [ "Error" : "Can't get the data!"]
                  self.response_json.append(errorJson)
                  self.response()
                  return
              }
              let json = JSON(data: response.data!)
              // get and print the title
              if json != nil{
                  self.response_json.append(json)
                  self.response()
              } else {
                  let errorJson: JSON = [ "Error" : "Can't get the data!"]
                  self.response_json.append(errorJson)
                  self.response()
                  return
              }
      }
  }
  </code></pre>