@iboutlet var txtusername: uitextfield! @iboutlet var txtpassword: uitextfield! @ibaction func signintapped(sender: uibutton) { var username:nsstring = txtusername.text var password:nsstring = txtpassword.text if (self.txtusername.text.isempty) { (uialertview(title: "fields cant empty", message: "please enter email id , password", delegate: nil, cancelbuttontitle: "ok").show()) return } else if (range==nil) { (uialertview(title: "invalid email id", message: "please enter correct email id", delegate: nil, cancelbuttontitle: "ok").show()) return } else if (txtpassword.text == "" ) { var alertview:uialertview = uialertview() alertview.title = "failed!" alertview.message = "please enter password" alertview.delegate = self alertview.addbuttonwithtitle("ok") alertview.show() return } else { var url:nsurl = nsurl(string:"http://192.168.0.31:8097/api/user/getvalidateuser" + "/" + username + "/" + txtpassword.text)! var err:nserror? var request:nsmutableurlrequest = nsmutableurlrequest(url: url) request.httpmethod = "get" request.addvalue("application/json", forhttpheaderfield: "content-type"); request.addvalue("application/json", forhttpheaderfield: "accept"); var reponseerror: nserror? var response: nsurlresponse? var urldata: nsdata? = nsurlconnection.sendsynchronousrequest(request, returningresponse:&response, error:&reponseerror) if ( urldata != nil ) { let res = response nshttpurlresponse!; var responsedata:nsstring = nsstring(data:urldata!, encoding:nsutf8stringencoding)! nslog("response code: %ld", res.statuscode); //var message :string = "valid user" if (res.statuscode == 200) { if(responsedata != "\"valid user\"") { var alertview:uialertview = uialertview() alertview.title = "failed" alertview.message = responsedata alertview.delegate = self alertview.addbuttonwithtitle("ok") alertview.show() return; } //get address book reference //gabberscontroller().getaddressbook() // var alertview:uialertview = uialertview() // alertview.title = "sign in message" // alertview.message = responsedata // alertview.delegate = self // alertview.addbuttonwithtitle("ok") // alertview.show() } else { var alertview:uialertview = uialertview() alertview.title = "failed" alertview.message = responsedata; if let error = reponseerror { alertview.message = (error.localizeddescription) } alertview.delegate = self alertview.addbuttonwithtitle("ok") alertview.show() } } else { var alertview:uialertview = uialertview() alertview.title = "failed" alertview.message = "connection failure"; if let error = reponseerror { alertview.message = (error.localizeddescription) } alertview.delegate = self alertview.addbuttonwithtitle("ok") alertview.show() } //self.performseguewithidentifier:@"goto__gabbers" sender:self; } }
for above code got sudden error, thought may missed reference outlet deleted existing 1 , created again in story board when run application same error throwing not getting missed here. executed @ first time further not,throwing fatal unexpected nil error can tell missed here.
this exact error getting:
fatal error: unexpectedly found nil while unwrapping optional value
posted full code
as per swift1.2 can below.
@iboutlet var txtusername: uitextfield! @iboutlet var txtpassword: uitextfield! @ibaction func signintapped(sender: uibutton) { if let username = txtusername.text as? string, let password = txtpassword.text as? string { var url:nsurl = nsurl(string:"http://192.168.0.31:8097/api/user/getvalidateuser" + "/" + username + "/" + password)! var err:nserror? } }
Comments
Post a Comment