i have wrapped 2 of api requests promise<t> return types:
func registerwithemail(email: string, firstname: string, lastname: string, password: string, subscribe: bool) -> promise<bool> func requestaccesstokenwithemail(username: string, password: string) -> promise<string> using them individually works fine:
firstly { client.registerwithemail("foo@gmail.com", firstname: "john", lastname: "smith", password: "password", subscribe: false) }.then { success -> void in completion(success: success) }.catch { error -> void in println(error.localizeddescription) } and:
firstly { client.requestaccesstokenwithemail("foo@gmail.com", password: "password") }.then { accesstoken -> void in println(accesstoken) completion(success: true) }.catch { error -> void in println(error.localizeddescription) } however, when chain them, token argument second then call never populated:
firstly { client.registerwithemail(username, firstname: "a", lastname: "b", password: password, subscribe: false).then { success -> void in return client.requestaccesstokenwithemail(username, password: password) }.then { accesstoken -> void in println(accesstoken) completion(success: true) } } if break inside closure can't view accesstoken argument, outer completion closure. however, if break inside requestaccesstokenwithemail function, accesstoken argument populated when calling fulfill.
i'm quite new promisekit, please let me know if i'm doing stupid.
i'm using promisekit 2.0, swift 1.2, xcode 6.4
the problem signature of first then closure.
it success -> void needed success -> promise<string>
i thought would've been caught swift's type inference forgot then overloaded accept closures of both (t) -> promise<u> , (t) -> u.
hopefully when swift fixes need explicit signature in then closure automatically inferred.
Comments
Post a Comment