Error NSMutableURLRequest swift

0

I have this code:

let urlString = "https://roads.googleapis.com/v1/snapToRoads?path="
let url = URL(string: urlString)
print(url)// Escribe=> nil
let request = NSMutableURLRequest(url:url)//Aqui da error

the error it gives is: fatal error: unexpectedly found nil while unwrapping an Optional value

The problem I think is the length of the url. what happened many parameters

    
asked by 20.10.2016 в 13:36
source

1 answer

0

The problem is that you are using an optional value, and the optional values can return a null, to avoid this you can do the following

let urlString = "https://roads.googleapis.com/v1/snapToRoads?path="
        let url = URL(string: urlString)
        print(url!)// Escribe=> nil
        let request = NSMutableURLRequest(url:url!)//Aqui forzas que no exista nulo

Print: link

    
answered by 20.10.2016 в 15:48