Alamofire Error After updating to latest version

2019-07-26 02:43发布

I am facing an issue an issue after updating to the latest version of Alamofire 4.x where by the myRequest.response (line 2) gives error 'Cannot call value of non-function type 'HTTPURLResponse?'. I have been using this code without any issues for quite some time. Can someone please help?

let queue = DispatchQueue(label: "com.cnoon.manager-response-queue", attributes: DispatchQueue.Attributes.concurrent)        
let myRequest = Alamofire.request(myURL, method: .get, headers: headers)
        myRequest.response (
            queue: queue,
            responseSerializer: Request.JSONResponseSerializer(options: .allowFragments),
            completionHandler:
            { response in
                switch response.result {
                case .success:
                    print(response.timeline)
                    if let httpStatusCode = response.response?.statusCode {
                        switch (httpStatusCode) {
                        case 200:
                            if let myValue = response.result.value {
                                updateSuccessful = StorageMethod.sharedInstance.updateRoutine(JSON(myValue))
                                print(updateSuccessful)
                                print("HERE")
                                //print(myJSON)
                                //let status_m = myJSON["dates"]["market_status"].stringValue
                                //print(status_m)
                            }
                        case 401:
                            customErrorMessage = "Session expired: Please exit app and re-login."
                            updateSuccessful = false
                        default:
                            customErrorMessage = "Error: Please try again."
                            updateSuccessful = false
                        }
                    }
                case .failure(let error):
                    if error.code == -1009 {
                        updateSuccessful = false
                        customErrorMessage = error.localizedDescription
                    }
                    else {
                        updateSuccessful = false
                        customErrorMessage = error.localizedDescription + "Hi"
                    }

                    //print(error)

                }

                DispatchQueue.main.async {

                    if (updateSuccessful) {
                        self.refreshMasterData()
                    }

                    else {
                        self.refreshMasterData()
                        if let tabControl = self.tabBarController?.view {
                            tabControl.makeToast(customErrorMessage, duration: 3.0, position: .center)
                        }
                    }

                    if (self.refreshControl.isRefreshing) {
                        self.showRefreshControl(false)
                    }

                    self.delegate?.portfolioTableViewControllerRefreshDrag(false)
                    StorageMethod.sharedInstance.dataUpdating = false
                }
            }

        )

0条回答
登录 后发表回答