4

是代码...

login().then {

    // our login method wrapped an async task in a promise
    return API.fetchKittens()

}.then { fetchedKittens in

    // our API class wraps our API and returns promises
    // fetchKittens returned a promise that resolves with an array of kittens
    self.kittens = fetchedKittens
    self.tableView.reloadData()

}.catch { error in

    // any errors in any of the above promises land here
    UIAlertView(…).show()

}

查看该then方法如何不返回任何内容。

当我使用then编译器时说我必须返回一个承诺。为什么我没有选择不这样做?

当我直接添加一个 catch 子句时,错误就消失了。嗯?

4

2 回答 2

3
于 2018-04-24T16:00:56.100 回答
3

在这里回答。

-> Void在我的闭包参数之后添加。

.then { fetchedKittens -> Void in }
于 2015-10-27T14:54:10.513 回答