相关疑难解决方法(0)

无法使用带有完成处理程序的函数进行抛出

我正在尝试throws使用完成处理程序向我的现有函数添加一个但我不断收到警告说no calls throwing functions occur within try expression.在我抛出错误的部分,我得到一个错误说

从抛出'()throw - > Void'类型的函数到非投掷函数类型的无效转换.

enum LoginError: ErrorType {
    case Invalid_Credentials
    case Unable_To_Access_Login
    case User_Not_Found
}

@IBAction func loginPressed(sender: AnyObject) {

    do{
        try self.login3(dict, completion: { (result) -> Void in

            if (result == true)
            {
                self.performSegueWithIdentifier("loginSegue", sender: nil)
            }
        })
    }
    catch LoginError.User_Not_Found
    {
        //deal with it
    }
    catch LoginError.Unable_To_Access_Login
    {
        //deal with it
    }
    catch LoginError.Invalid_Credentials
    {
        //deal with it
    }
    catch
    {
        print("i dunno")
    }

}

func …
Run Code Online (Sandbox Code Playgroud)

error-handling asynchronous try-catch swift swift2

10
推荐指数
1
解决办法
4309
查看次数

标签 统计

asynchronous ×1

error-handling ×1

swift ×1

swift2 ×1

try-catch ×1