I have the following function to call a URL that is in a REST from Swift 2, but when I send values with space in the NSURL I get the following error:
fatal error: unexpectedly found nil while unwrapping an Optional value
class func getApi(urlWithArgs: String?) -> NSMutableURLRequest {
let url: NSURL = NSURL(string: urlWithArgs!)!
let resquest = NSMutableURLRequest(URL: url)
return resquest
}
What am I wrong with for this error to appear only when I send values with a space? Example, I send a name: "pepito perez". Why does sending "pepitoperez" work?
Thanks