ios - unexpectedly found nil while unwrapping an Optional value in webservice code -
i have binded login action , tried call restfull webservice.
below code:
@ibaction func loginaction(sender: anyobject) { println(emailtextfield.text) println(pwdtextfield.text) let plaindata = emailtextfield.text.datausingencoding(nsutf8stringencoding) let base64string = plaindata?.base64encodedstringwithoptions(.allzeros) println(base64string) let plaindatapwd = pwdtextfield.text.datausingencoding(nsutf8stringencoding) let base64stringpwd = plaindatapwd?.base64encodedstringwithoptions(.allzeros) println(base64stringpwd) var urlpath = "http://inspect.dev.cbre.eu/syncservices/api/jobmanagement/pluscontactauthentication?email=\(base64string)&userpwd=\(base64stringpwd)" var url: nsurl! = nsurl(string: urlpath) var request: nsurlrequest = nsurlrequest(url: url) var connection: nsurlconnection! = nsurlconnection(request: request, delegate: self,startimmediately: false) connection.start() }
i found nil while unwrapping optional value in webservice
try code:
@ibaction func login(sender: anyobject) { println(txt1.text) println(txt2.text) let base64string : nsstring = "" let base64stringpwd : nsstring = "" if let plaindata = txt1.text.datausingencoding(nsutf8stringencoding){ let base64string = plaindata.base64encodedstringwithoptions(.allzeros) println(base64string) } if let plaindatapwd = txt2.text.datausingencoding(nsutf8stringencoding){ let base64stringpwd = plaindatapwd.base64encodedstringwithoptions(.allzeros) println(base64stringpwd) } var urlpath : nsstring? = "http://inspect.dev.cbre.eu/syncservices/api/jobmanagement/pluscontactauthentication?email=\(base64string)&userpwd=\(base64stringpwd)" var url = nsurl(string: urlpath!) if let url1 = url{ var request: nsurlrequest = nsurlrequest(url: url1) var connection: nsurlconnection! = nsurlconnection(request: request, delegate: self,startimmediately: false) connection.start() } } }
Comments
Post a Comment