私は約束を返す関数を書こうとしています:
func sample() -> Promise<AnyObject> {
return Promise(1)
.then { _ -> Void in
debugPrint("foo")
}.then { _ -> Void in
debugPrint("foo")
}
}
最後の then ステートメントでエラーが発生します。
Declared closure result 'Void' (aka '()') is incompatible with contextual type 'AnyPromise'
私は、'then' は黙示的にプロミスを返さなければならないという印象を受けました。私の考えは間違っていますか?このように明示的に promise を返す必要がありますか?:
func sample() -> Promise<AnyObject> {
return Promise(1)
.then { _ -> Void in
debugPrint("foo")
}.then { _ -> Promise<AnyObject> in
debugPrint("foo")
return Promise(1)
}
}
ありがとう