I'm getting this error passing optional:
fatal error: unexpectedly found nil while unwrapping an Optional value
Here is my code:
func makeRequestcompletion(completion:@escaping (_ response:Data, _ error:NSError)->Void) {
let urlString = URL(string: "https://myUrl.com")
if let url = urlString {
let task = URLSession.shared.dataTask(with: url, completionHandler: { (data, urlRequestResponse, error) in
completion((data)!, error as! NSError) // <-- here is where I'm getting the error
})
task.resume()
}
}
Any of you knows why I'm getting this error?
I'll really appreciate your help.