0

I am migrating from promiseKit 4.3 -> 6 and got stuck on this one error. Any help would be appreciated. Thanks

error - "Cannot convert value of type '() -> Environment' to expected argument type '() -> _'"

open func run() -> Promise<Environment> {
    return GetSettingsQuery().run().then { result -> Environment in
        var environment = Environment.certification

        if let dict = result.data as? Dictionary<String, AnyObject>,
            let environementRaw = dict[“ABC”] as? Int,
            let env = Environment(rawValue: environementRaw) {
            environment = env
        }
        return environment
    }
}
satish
  • 21
  • 2

1 Answers1

2

As both the migration guide and troubleshooting guides from the PromiseKit documentation say, you need to replace the then with map

open func run() -> Promise<Environment> {
    return GetSettingsQuery().run().map { result -> Environment in
        var environment = Environment.certification

        if let dict = result.data as? Dictionary<String, AnyObject>,
            let environementRaw = dict[“ABC”] as? Int,
            let env = Environment(rawValue: environementRaw) {
            environment = env
        }
        return environment
    }
}

It is generally recommended to read a project’s documentation especially if you are upgrading the major version of a project.

NEVER upgrade a major version of a library without reading the release notes first, the release notes for v6 of PromiseKit describe your exact problem multiple times.

Pin your dependencies to major versions, ALL package managers support this and the documentation for ALL package managers tell you to pin your dependency major versions.

mxcl
  • 26,392
  • 12
  • 99
  • 98