繁体   English   中英

在Alamofire中使用来自上一个异步HTTP请求的响应数据

[英]Using response data from last async HTTP Request with Alamofire

我目前正在使用Alamofire向服务器发出异步http请求,以取回一些数据。 但是,我几乎同时向服务器发出了3个请求,我只想使用我上次发出的请求中的数据。 但是,我遇到的问题是第三个请求之后前两个请求完成。 因此,它导致使用前2个请求中的数据。

    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)
        }
    })

有谁知道如何解决这个问题? 谢谢!

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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