为什么我必须回复承诺?

时间:2015-10-27 14:12:55

标签: swift promisekit

Here是代码......

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子句时,错误消失了。啊?

2 个答案:

答案 0 :(得分:3)

回答here

我在封闭参数之后添加了-> Void

.then { fetchedKittens -> Void in }

答案 1 :(得分:2)

You should use .done{} to finish promise chain, like this:

.done { fetchedKittens -> Void in }

.then{} with -> Void is not working anymore, because .then{} always need to return promise.

Documentation