4

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?

Ian Warburton
  • 15,170
  • 23
  • 107
  • 189
  • 2
    You might want to specify your types more precisely, as stated in the documentation http://promisekit.org/PromiseKit-2.0-Released/ (apparently the inference in inner closures is not perfect) – Jozef Legény Oct 27 '15 at 14:31
  • Answer here... https://github.com/mxcl/PromiseKit/issues/210. I added '-> Void' after the closure parameters. – Ian Warburton Oct 27 '15 at 14:52

2 Answers2

3

Answer here.

I added -> Void after my closure parameter.

.then { fetchedKittens -> Void in }
Ian Warburton
  • 15,170
  • 23
  • 107
  • 189
3

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

Samvel Aleqsanyan
  • 2,812
  • 4
  • 20
  • 28