我正在尝试编写一个返回承诺的函数:
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”都应该隐含地返回一个承诺;我的想法错了吗?我应该像这样明确地返回一个承诺吗?:
func sample() -> Promise<AnyObject> {
return Promise(1)
.then { _ -> Void in
debugPrint("foo")
}.then { _ -> Promise<AnyObject> in
debugPrint("foo")
return Promise(1)
}
}
谢谢