I'm trying to use PromiseKit with Swift. I am not really familiar with it, and there doesn't seem to be much information on its usage with Swift.
I can't seem to figure out how to terminate a chain of promises. As long as the last (terminal) then
block contains a single statement, everything is fine:
firstly {
// ...
}.then { obj in
self.handleResult(obj)
}.catch { error in
self.handleError(error)
}
However, if I try to add another statement, compiler complains:
firstly {
// ...
}.then { obj in
self.handleResult(obj)
self.doSomethingDifferent(obj)
}.catch { error in // compiler error: Missing return in a closure expected to return 'AnyPromise'
self.handleError(error)
}
Obviously, the solution is to return another promise, but it doesn't make sense in the terminal block. Is there anything else I can do?
According to http://promisekit.org/PromiseKit-2.0-Released/, under Swift Compiler Issues section:
So you'll have to change your code to:
Or you can use
obj -> Void
to stop the chain