0

how to covert URLRequest to Alamofire URLConvertible I am getting error while trying to convert following is my code

var request = URLRequest(url: URL(string: "some url")!)
request.httpBody = json
RxAlamofire.request(.post, request as! URLConvertible, parameters: param, encoding: JSONEncoding.default, headers: ["Content-Type" : "application/json"])
    .subscribe(onNext:{ [weak self] (json) in
        print(json)
        if let jsonResult = JSON(json) as? JSON {
            if let cartResult = FoodCartResult(jsonResult) as? FoodCartResult {
                self?.delegate?.showCart(cartresult: cartResult)
            }
        }

        }, onError: {
            [weak self] (error) in
            print(error.localizedDescription)
            self?.delegate?.onError()
        },onCompleted: {})
    .disposed(by: disposeBag)

code is crashing my app saying

Could not cast value of type 'Foundation.URLRequest' (0x10c23a3c8) to 'Alamofire.URLConvertible'

Already referred following but not working for me Could not cast value of type 'NSMutableURLRequest' (0x11beb7040) to 'Alamofire.URLRequestConvertible' (0x11beb9040)

rmaddy
  • 314,917
  • 42
  • 532
  • 579
alphanso
  • 409
  • 5
  • 22

0 Answers0