swift2 - NSURL always returning nil Swift 2.0 -
in app making, have line of code looks this:
let url = nsurl(string: "https://website.com/api/loginauth?username=\(usernamefield.text)&password=\(passwordfield.text)") let session = nsurlsession(configuration: nsurlsessionconfiguration.defaultsessionconfiguration()) let request = nsurlrequest(url: url!)
every time code gets executed, app crashes error looks this:
fatal error: unexpectedly found nil while unwrapping optional value
the url not nil, crashes each time when unwrapping url @ nsurlrequest().
thanks in advance
thanks eric d. , vadian answering question, answer usernamefield.text , passwordfield.text need unwrapped, when did this, worked perfectly:
let url = nsurl(string: "https://website.com/api/loginauth?username=\(usernamefield.text!)&password=\(passwordfield.text!)") let session = nsurlsession(configuration: nsurlsessionconfiguration.defaultsessionconfiguration()) let request = nsurlrequest(url: url!)
thanks -
Comments
Post a Comment