I'm a long-time developer, but pretty new to Swift. I'm trying to get information from a web service (and found code online that I adjusted to build the function below). (Note: AAA_Result -- referenced towards the end -- is another class in my project)
Trouble is, I'm getting the subject error on the call to session.dataTask. Any help/suggestions/doc pointers will be greatly appreciated!!!
var result: Bool = false
var cancellable: AnyCancellable?
self.name = name
let params = "json={\"\"}}" // removed json details
let base_url = URL(string: "https://aaa.yyy.com?params=\(params)&format=json")! // removed URL specifics
do {
let task = URLSession.shared.dataTask(with: base_url) { data, response, error in
if let error = error {
print("Error: \(error)")
}
guard let response = response as? HTTPURLResponse, (200...299).contains(response.statusCode)
else {
print("Error \(String(describing: response))")
}
do {
let decoder = JSONDecoder()
let ar = try decoder.decode(AAA_Result.self, from: response.value)
// removed specific details...
result = true
}
catch {
print(error)
}
}
task.resume()
}
catch {
print(error)
}
return result
}