title: How to order an array only after it has been filled
body: <pre><code>   func getOkToDownload(response:AcloseCarsToDownload?, error : Error?) -&gt; Void {
  
          if let response = response {
             self.response = response
              if response.status == "OK" {
                  if let carsDownloaded = response.cars {
                      var number = numberCars / (categories?.count)!
                      number = number == 0 ? 1 : number
  
                   let sortedArray = carsDownloaded.sorted {
                              distance(from: currentLocation!, to: $0.location!) &lt; distance(from: currentLocation!, to: $1.location!)
                      }
  
  
                  /*    let firstPlace = sortedArray.prefix(1) */
  
  
  
  
                    cars.append(contentsOf: sortedArray.prefix(number))
  
              }
                 self.tableView?.reloadData()
              } else {
                  let alert = UIAlertController.init(title: "Error", message: response.status, preferredStyle: .alert)
                  alert.addAction(UIAlertAction.init(title: "Cancel", style: .cancel, handler: nil))
                  alert.addAction(UIAlertAction.init(title: "Retry", style: .default, handler: { (action) in
                      DispatchQueue.main.async {
                          self.loadPlaces(true)
  
                      }
                  }))
                   self.present(viewController: alert)
                  }
              isLoading = false
          }
          else {
              print("response is nil")
          }
      }
  </code></pre>
  
  <p>I'm using this function to create a list <code>cars.append(contentsOf: sortedArray.prefix(number))</code> of downloaded items from a server; and i want that this list is ordered from nearest to fairest item so i thought to order it by adding   </p>
  
  <pre><code>let sortedArray = carsDownloaded.sorted {
                              distance(from: currentLocation!, to: $0.location!) &lt; distance(from: currentLocation!, to: $1.location!)
                      }
  </code></pre>
  
  <p>but the problem with this solution is that it sorts the list at each call and the result is not the desired one, i wish that only once finished and the array is filled, the list will be ordered. How can i do?</p>
  
  <p>This is the func i used for the call</p>
  
  <pre><code>func loadCars(_ force:Bool) {
  
          if !force {
              if !canUpdate() {
                  return
              }
          }
  
           if(force){
          print("load")
          iUpdating = true
           for category in categories! {
  
              CloseCars.getCloseCars(by: category?.name ?? "berl", coordinates: currentLocation!, radius: radius, token: self.response?.nextPageToken, completion: getOkToDownload)
  
         }
      }
   }
  </code></pre>