Reputation: 621
I have been sitting for a while with this error , i even checked stack overflow similar questions but non helped. I am getting this error and i do not know what i am doing wrong.
This is the eror image, due to less points i cant post it but i can embed a this link.
This is my code where the error is occurring :
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!)
}
}
....
Service call class :
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()
}
}
Upvotes: 0
Views: 72
Reputation: 325
Hmm, fetchJson
doesn't have a completion parameter, but when you called it, you write:
{ (ok, json) in
Please change your function declaration to this:
func fetchJson(request: URLRequest, customerCountry: String, mobileNumber: String, completion: ((Bool, Dictionary<String, Any>?) -> Void)?)
Upvotes: 1