【发布时间】:2018-04-24 11:19:51
【问题描述】:
我创建了一个 Promise,它从 API 获取一些数据并返回它。现在我遇到的问题是在获取我需要将它们存储在设备存储(领域)上的 json 数据之后。在我尝试调用 promise 之后,我得到一些错误,说明 Cannot convert value of type '(Any) -> Void' to expected argument type '(_) -> _' 。但是当我尝试完成它时,它工作得很好。但我需要使用 then 将数据保存在领域。
以下方法可以正常工作
Translator().translators().done { data -> Void in
print(data[0].name)
}.catch { error in
print(error)
}
但是以下两种方法都失败了
Translator().translators().then() { data -> Void in
print(data)
}.catch() {
(e: Error) in
print(e)
}
上面给出了一个错误提示
Cannot convert value of type '(Any) -> Void' to expected argument type '(_) -> _'
以下方法给出了另一个类似的错误
Translator().translators().then() {
(data: [Translator]) -> Void in
print(data[0].name)
}.catch() {
(e: Error) in
print(e)
}
错误信息:
Cannot convert value of type '([Translator]) -> Void' to expected argument type '([Translator]) -> _'
我创造的承诺:
func translators() -> Promise<[Translator]> {
return firstly {
Alamofire.request("http://192.168.0.107:3000/translatdors", method: .get).responseData()
}.map {
try JSONDecoder().decode([Translator].self, from: $0.data)
}
}
【问题讨论】:
标签: ios swift promisekit