title: How to handle priorities in a Swifty JSON Alamofire request?
body: <p>How can I use the dispatchQueue or something like "await" in Javascript to return a value in <code>self.arrayData</code> (because the end of my loop is ran before the previous content). I am used to R and Python where the code runs line by line, What is the best behavior to adopt in Swift ? </p>
  
  <p>Here is the function : </p>
  
  <pre><code>func fetch2(){
  
      var i:Int = 0
  
      repeat {
  
      AF.request(itemLookUp[i]).validate().responseJSON { response in
  
      switch response.result {
  
      case .failure(let error):
      print("\(error) in fetch2")
  
      case .success(let value):
  
          let json = JSON(value)
  
          //Extract the Matiere for ML Extraction
      self.matiereInput = json["ResultSet"]["0"]["Result"]["0"]["SpAdditional"].string ?? "none"
  
          let energyCheck:Bool = self.matiereInput.contains("エネルギー") //energy-kcal
  
      if energyCheck==true &amp;&amp; self.arrayData[0]==0.0{
          //regular expression
          var patEnergy = #"(エネルギー)(([^\d]+)(\d+)(\.)(\d+)|([^\d]+)(\d+))"# //avoid the repetition of the pattern within the same matiereinput
          let patEnergy2 = self.matches(for: patEnergy, in: self.matiereInput)
          patEnergy = patEnergy2.joined(separator:"")
          let valueEnergy = self.matches(for: self.regex2, in: patEnergy)
          self.arrayData[0] = Double(valueEnergy.joined(separator: "")) ?? 0.0
          }
  
      }
          }
          i = i+1
          print(self.arrayData[0])
  } while i &lt;= (self.returned-1)
  }
  </code></pre>
  
  <p>Thank you in advance !</p>