Hi, I'm doing a simple app to learn how to use WebService but I have a problem.
On the line where I initialize task
I get the following error when I execute it and I give the button to call the service .
Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value
func llamadaWebService(){
let urlPath = "http://api.openweatherapp.rg/data/2.5/weather?q=\(String(describing: captura.text))"
let url = URL(string: urlPath)
let session = URLSession.shared
let task = session.dataTask(with: url!) { (data, response, error) in
if(error != nil) {
//Imprime error si no está vacío . Si hay error es que hubo error en la conexión
print("error")
}
let nsdata:NSData = NSData(data: data!)
print(nsdata)
// self.recuperarClimaDeJson(nsdata)
}
task.resume()
}
Thanks in advance.