簡體   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