ios - Swift 2: "the error is not handled" -
this question has answer here:
- issue swift 2 error handling 1 answer
started
"call can throw not marked try , error not handled"
error after updated xcode 6.4 7 swift2 in "contactusobject.save()"
. how can fix this?
@ibaction func postcommentbtn_clicked(sender: anyobject) { if messagetxtcomment.text.isempty { let alertview = uialertcontroller(title: "message field empty", message: "please enter message post", preferredstyle: .alert) alertview.addaction(uialertaction(title: "ok", style: .default, handler: nil)) self.presentviewcontroller(alertview, animated: true, completion: nil) } else { var thecomment = messagetxtcomment.text let len = messagetxtcomment.text.utf16.count if len > 150 { thecomment = thecomment.substringtoindex(thecomment.startindex.advancedby(150)) } let contactusobj = pfobject(classname: "contactusmessage") contactusobj["username"] = pfuser.currentuser()!.username contactusobj["email"] = pfuser.currentuser()!.valueforkey("email") as! string contactusobj["name"] = namefield.text contactusobj["enteredemail"] = emailfield.text contactusobj["phonenum"] = phonefield.text contactusobj["message"] = thecomment contactusobj.save() } }
do { try contactusobj.save() } catch error nserror { print(error) //handle error. }
Comments
Post a Comment