【问题标题】:PromiseKit unseen type conversion for NSDictionaryNSDictionary 的 PromiseKit 看不见的类型转换
【发布时间】:2018-04-03 08:27:16
【问题描述】:

我正在尝试从我的路径中获取一个 json。一切似乎都是正确的(假设我来自 Swift 2 并尝试更新到 Swift 4)但是,事情似乎出了问题。

class func getPlayerStatuses(sportName: String) -> Promise<[NSDictionary]> {
    let path = "api/sports/player-status/\(sportName)/"
    return API.get(path).then { (json: NSDictionary) -> [NSDictionary] in
        let playerUpdates: [NSDictionary] = try json.get("player_updates")
        return playerUpdates
    }
}

我收到以下错误。

Cannot convert value of type '(NSDictionary) throws -> [NSDictionary]' to expected argument type '(_) throws -> _'

有人知道为什么我会收到关于类型转换的错误吗?

【问题讨论】:

  • 您使用什么版本的 PMK?
  • @pacification PromiseKit 版本 6

标签: ios swift swift4 promisekit


【解决方案1】:

PMK 6 中更改了返回非承诺值的方式(参见Why PromiseKit 5/6? 部分)。现在你应该使用map 而不是then 来完成这种工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-17
    • 1970-01-01
    • 2017-07-01
    相关资源
    最近更新 更多