Try and catch Error with Parse.com

荒凉一梦 提交于 2019-12-13 10:25:11

问题


I need some help with this:

func checkUserCredentials() -> Bool{
      PFUser.logInWithUsername(userName!, password: Contraseña!)
       if (PFUser.currentUser() != nil){
            return true
        }
        return false
   }

It says that PFUser.logInWithUsername(userName!, password: Contraseña!) has problems because its not marked with try ... and the error is not handled.


回答1:


func checkUserCredentials() -> Bool{
    do {
        try PFUser.logInWithUsername(userName!, password: Contraseña!)
    } catch{
        // deal here with errors
    } 
    return PFUser.currentUser() != nil ? true : false
}

As it is quite basic issue I recommend you reading some tutorials




回答2:


Just replace this

if (PFUser.currentUser() != nil) {

with

if let currentUser = try? PFUser.currentUser() {


来源:https://stackoverflow.com/questions/33039138/try-and-catch-error-with-parse-com

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!