1

Im trying to follow the Documentation to pass the result of a promise to the next promise

https://github.com/mxcl/PromiseKit/blob/master/Documentation/CommonPatterns.md#saving-previous-results

I keep getting
Contextual closure type '(_) throws -> _' expects 1 argument, but 2 were used in closure body

Here my Code

 class func loginInOrSignup() -> Promise<PFUser> {
        let lm = LoginManager()
        lm.logOut()

        return logInInBackground().then{user in
                if user.isNew{
                    return getUserInfo().map{ ($0, user) }
                }
                else{
                    user.fetchIfNeededInBackground()
                    return Promise.value(user)
                }
            }.then{(userInfo, user) -> Promise<PFUser> in

                let name = userInfo["name"] as! String
                if let email = userInfo["email"] as? String {
                    user.email = email
                }
                let username = G8FacebookLogin.generateSuggestedUsername(name: name)
                user.username = username

                return Promise.value(user)
            }
    }

    private class func logInInBackground() -> Promise<PFUser>{
        return Promise {seal in
            PFFacebookUtils.logInInBackground(withReadPermissions: ["public_profile", "email"]){user, error in
                guard let user = user else {
                    seal.reject(error ?? AuthError.msg(reason: "Some FB Error"))
                    return
                }
                seal.fulfill(user)
            }
        }
    }
    private class func getUserInfo() -> Promise<Dictionary<String,Any>> {
        return Promise {seal in
            G8FacebookLogin.getUserInfo { (userDict, error) in
                guard let userInfo = userDict else{
                    PFUser.logOut()
                    seal.reject(AuthError.loginFailed(reason: "no user Info retrieved"))
                    return
                }
                seal.fulfill(userInfo)
            }
        }
    }

enter image description here

It's pretty much the same as the Snippet code in the documentation. I don't understand what is the right way to do it.

omarojo
  • 1,197
  • 1
  • 13
  • 26
  • you have just one value in the `then` block -> `.then { user in }` – emrcftci Apr 07 '20 at 09:02
  • @emrcftci you mean here ? `logInInBackground().then{user in` but that function only returns 1 value, that one is fine. the problem is how do I pass 2 values to the next `then` after calling getUserInfo() – omarojo Apr 07 '20 at 09:06

0 Answers0