简体   繁体   中英

Using response data from last async HTTP Request with Alamofire

I am currently using Alamofire to make async http request to my server to get some data back. However, I am making like 3 requests to the server around the same time and I only want to use the data from the last request that I make. However, I am having this issue where the first 2 request gets completed after the 3rd request. Therefore, it resulted in using the data from the first 2 request.

    HttpService.makeGetRequestWithHeader(AppEndPoint.driverLocation, params: params, completionHandler: {(responseData, error) -> Void in
        if let data = responseData {
            self.cars.removeAll()

            let driverLocationListResponse: DriverLocationListResponse = DriverLocationListResponse.fromDictionary(data)
            var driverCars: [DriverCar] = []
            for driver in driverLocationListResponse.driverLocationList {
                let driverCar: DriverCar = DriverCar(driverId: driver.driverId!, latitude: driver.latitude!, longitude: driver.longitude!)
                driverCars.append(driverCar)
            }

            self.addCars(driverCars)
        }
    })

Does anyone know how to solve this issue? Thanks!

保留对此请求的引用,并在运行前将其取消。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM