how to throw errors in a closure in swift?

后端 未结 2 1739
别跟我提以往
别跟我提以往 2021-01-14 10:01

Please look at the following code:

override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRow         


        
2条回答
  •  春和景丽
    2021-01-14 10:22

    Not possible, because the closure can be invoked at any time, probably not at execution time of your function, so where should the error propagate to?

    You have to call out to another function which can handle the error:

    func handleError(error: ErrorType) {
        switch error {
            ...
        }
    }
    

    and then call this function with your caught error inside the closure

提交回复
热议问题