Search code examples
iosswiftswift4promisekit

PromiseKit unseen type conversion for NSDictionary


I'm attempting to fetch a json from my path. And everything seems right (granted I came from Swift 2 and tried updating to Swift 4) however, things seem to have gone awry.

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
    }
}

And I'm receiving the following error.

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

Does anyone have any clues as to why I'm getting errors about type conversion?


Solution

  • The way of returning non-promise value changed in PMK 6 (see Why PromiseKit 5/6? section). Now you should use map instead of then for this kind of work.