Here is the code...
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()
}
See how the then
method is not returning anything.
When I use then
the compiler is saying I must return a promise. Why don't I have the choice not to?
The error goes away when I add a catch clause straight after. huh?