【发布时间】:2016-09-11 00:56:56
【问题描述】:
我正在尝试编写一个返回承诺的函数:
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)
}
}
谢谢
【问题讨论】:
标签: swift promisekit