这是代码...
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 子句时,错误就消失了。嗯?