I am setting up my sign up and login page using parse on xcode with swift but i keep getting a fatal error. Can somebody see what im doing wrong? -
this have far:
import foundation import parse import uikit import bolts class signupviewcontroller: uiviewcontroller, uitextfielddelegate { @iboutlet weak var statuslabel: uilabel! @iboutlet weak var emailtextfield: uitextfield! @iboutlet weak var passwordtextfield: uitextfield! @iboutlet weak var createaccountbutton: uibutton! override func viewdidload() { super.viewdidload() // additional setup after loading view, typically nib. emailtextfield.delegate = self; passwordtextfield.delegate = self; } override func didreceivememorywarning() { super.didreceivememorywarning() // dispose of resources can recreated. } @ibaction func createaccountbuttonpressed(sender: anyobject) { if verifyemaildomain(self.emailtextfield.text) { createaccount(self.emailtextfield.text, password: self.passwordtextfield.text) } else { //self.statuslabel.text = "email domain not valid."; let alert = uialertview() alert.title = "invalid email domain" alert.message = "make sure entered in address correctly. if did, ask system using pagemd! thanks." alert.addbuttonwithtitle("close") alert.show() } } func verifyemaildomain(email: string) -> bool { var isverifieddomain = false let userdomain: string = (email.componentsseparatedbystring("@")).last! //nslog(userdomain) let validdomainsfilelocation = nsbundle.mainbundle().pathforresource("validdomains", oftype: "txt") var validdomainsfilecontent = nsstring(contentsoffile: validdomainsfilelocation!, encoding: nsutf8stringencoding, error: nil) // nslog(validdomainsfilecontent! string) let validdomains = validdomainsfilecontent!.componentsseparatedbystring("\n") domain in validdomains { nslog(domain as! nsstring string) if userdomain == (domain as? nsstring) { isverifieddomain = true break } } return isverifieddomain } func createaccount(email: string, password: string) { var newuser = pfuser() newuser.username = email // want user login email. newuser.email = email newuser.password = password newuser.signupinbackgroundwithblock { (succeeded: bool, error: nserror?) -> void in if error == nil { // account created successfully! if succeeded == true { self.statuslabel.text = "account created!" } } else { if let errorfield = error!.userinfo { self.statuslabel.text = (errorfield["error"] as! nsstring) string } else { // no userinfo dictionary present // http://stackoverflow.com/questions/25381338/nsobject-anyobject-does-not-have-a-member-named-subscript-error-in-xcode } } } } func textfieldshouldreturn(textfield: uitextfield) -> bool { textfield.resignfirstresponder() return true; } }
when run receive in terminal xcode:
fatal error: unexpectedly found nil while unwrapping optional value (lldb)
and highlighted in green is:
var validdomainsfilecontent = nsstring(contentsoffile: validdomainsfilelocation!, encoding: nsutf8stringencoding, error: nil)
what can avoid error? i'm trying create login uses emailverified feature parse keep receiving error , cant save email core or send verification email user. can make code work , stop error coming up?
in case, file @ validdominsfilecontent
wasn't found. need make sure file included in bundle.
to that, open bundle-resources:
project > app target > build phases > copy bundle resources
there save file. should found swift.
Comments
Post a Comment