When calling my function to fetch some locations from an API I'm getting the error "Type of expression is ambiguous without more context".
As I'm relatively new to iOS development and swift I have to ask you guys. Hope its just some simple thing I've overseen. I already searched the web, but nothing helped.
Thank you in advance!
Here is how I'm calling the function:
fetchLocation(latitude: latitude, longitude: longitude, locationsCompletionHandler: {
shopSites in
ForEach (shopSites){ }
})
And here is the function:
func fetchLocation(latitude: Double, longitude: Double, locationsCompletionHandler: @escaping ([ShopSite]) -> Void) {
let semaphore = DispatchSemaphore (value: 0)
let domain = "http://e2cadda8d178.ngrok.io/api/v1/"
let urlString = domain + "public/location/" + String(latitude) + "/" + String(longitude) + "/50"
//let url = URL(string: "e2cadda8d178.ngrok.io/api/v1/public/location/66.68994/10.249066/50")!
let url = URL(string: urlString)!
var request = URLRequest(url: url,timeoutInterval: Double.infinity)
request.httpMethod = "GET"
let task = URLSession.shared.dataTask(with: request) { json, response, error in
guard let json = json else {
print(String(describing: error))
semaphore.signal()
locationsCompletionHandler([])
return
}
let str = String(decoding: json, as: UTF8.self)
print(str)
let shopSites: [ShopSite] = try! JSONDecoder().decode([ShopSite].self, from: json)
print(shopSites.count)
semaphore.signal()
locationsCompletionHandler(shopSites)
}
task.resume()
semaphore.wait()
Let me now if you need further details.