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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -