I'm trying to write a function that returns a promise:
func sample() -> Promise<AnyObject> {
return Promise(1)
.then { _ -> Void in
debugPrint("foo")
}.then { _ -> Void in
debugPrint("foo")
}
}
I get an error on the last then statement:
Declared closure result 'Void' (aka '()') is incompatible with contextual type 'AnyPromise'
I was under the impression that 'then' should implicitly returned a promise regardless; Is my thinking wrong? Should I just return a promise explicitly like so?:
func sample() -> Promise<AnyObject> {
return Promise(1)
.then { _ -> Void in
debugPrint("foo")
}.then { _ -> Promise<AnyObject> in
debugPrint("foo")
return Promise(1)
}
}
Thanks