额外的论点' mobileNumber'在电话中

时间:2018-04-09 17:34:26

标签: ios swift mode

我已经坐了一会儿这个错误,我甚至检查了堆栈溢出类似的问题,但没有帮助。我收到这个错误,我不知道我做错了什么。

这是一个错误的图片,由于我发布的点数较少,但我可以嵌入此链接。 This is the eror image, due to less points i cant post it but i can embed a this link.

这是我发生错误的代码:

class SearchViewModelFromSearchResult: SearchCustomerModel 
{

    var search: SearchResultObj?

    init() 
    {
        self.search = SearchResultObj()
    }

    func searchDataRequested(_ apiUrl: String,_ country: String,_ phone:String) 
    {

        let service = ServiceCall(urlServiceCall: apiUrl, country: country, phone: phone)
        let url = URL(string: apiUrl)
        let request = URLRequest(url: url!)
        let country = country
        let phone = phone

        service.fetchJson(request: request, customerCountry: country, mobileNumber: phone)
         { (ok, json) in
            print("CallBack response : \(String(describing: json))")
            self.jsonMappingToSearch(json!)
        }
    }
....

服务电话类:

class ServiceCall: NSObject, ServiceCallProtocol, URLSessionDelegate 
{
    let urlServiceCall: String?
    let country: String?
    let phone: String?

    init(urlServiceCall: String,country: String, phone: String)
    {
        self.urlServiceCall = urlServiceCall
        self.country = country
        self.phone = phone
    }

    func fetchJson(request: URLRequest, customerCountry: String, mobileNumber: String)
    {
        let searchParamas = CustomerSearch.init(country: customerCountry, phoneNumber: mobileNumber)
        var request = request
        request.httpMethod = "POST"
        request.httpBody = try?  searchParamas.jsonData()
        request.addValue("application/json", forHTTPHeaderField: "Content-Type")

        let session = URLSession.shared
        let task = session.dataTask(with: request, completionHandler: { data, response, error -> Void in
            do {
                let json = try JSONSerialization.jsonObject(with: data!) as! Dictionary<String, Any>
                let status = json["status"] as? Bool
                if status == true {

                }else{

                }
            } catch {
               print("Unable to make an api call")
            }
        })

        task.resume()
    }
}

1 个答案:

答案 0 :(得分:1)

嗯,fetchJson没有完成参数,但是当你调用它时,你会写:

{ (ok, json) in

请将您的功能声明更改为:

func fetchJson(request: URLRequest, customerCountry: String, mobileNumber: String, completion: ((Bool, Dictionary<String, Any>?) -> Void)?)