Swift Alamofire Request Error - Extra Argument in call

99封情书 提交于 2019-12-25 08:41:01

问题


I am getting an error when I am trying to request using Alamofire. The error says that there is an 'extra argument in call'.

class SwiftStockKit {

class func fetchStocksFromSearchTerm(term: String, completion:@escaping (_ stockInfoArray: [StockSearchResult]) -> ()) {
    DispatchQueue.global(priority: DispatchQueue.GlobalQueuePriority.default).async {

        let searchURL = "http://autoc.finance.yahoo.com/autoc"

        Alamofire.request(.GET, searchURL, parameters: ["query": term, "region": 2, "lang": "en"]).responseJSON { response in

            if let resultJSON = response.result.value as? [String : AnyObject]  {

                if let jsonArray = (resultJSON["ResultSet"] as! [String : AnyObject])["Result"] as? [[String : String]] {

                    var stockInfoArray = [StockSearchResult]()
                    for dictionary in jsonArray {
                        stockInfoArray.append(StockSearchResult(symbol: dictionary["symbol"], name: dictionary["name"], exchange: dictionary["exchDisp"], assetType: dictionary["typeDisp"]))
                    }

                    dispatch_async(dispatch_get_main_queue()) {
                        completion(stockInfoArray: stockInfoArray)
                    }
                }
            }
        }
    }
}

The line that is giving me an error is:

Alamofire.request(.GET, searchURL, parameters: ["query": term, "region": 2, "lang": "en"]).responseJSON { response in

if anyone could fix this I would be really grateful, thanks


回答1:


Try change your request to something like this:

Alamofire.request(searchURL, method: .get, parameters: ["query": term, "region": 2, "lang": "en"], encoding: JSONEncoding.default, headers: nil)


来源:https://stackoverflow.com/questions/44704860/swift-alamofire-request-error-extra-argument-in-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!