我是 Swift 中的 Promise 的新手,我使用 PromiseKit 尝试在操场上创建一个非常简单的响应并尝试使用它。我有以下代码:
import UIKit
import PromiseKit
func foo(_ error: Bool) -> Promise<String> {
return Promise { fulfill, reject in
if (!error) {
fulfill("foo")
} else {
reject(Error(domain:"", code:1, userInfo:nil))
}
}
}
foo(true).then { response -> String in {
print(response)
}
}
但是我收到以下错误:
error: MyPlayground.playground:11:40: error: cannot convert value of type '() -> ()' to closure result type 'String'
foo(true).then { response -> String in {