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子句时,错误消失了。啊?
答案 0 :(得分:3)
答案 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.