【发布时间】:2015-10-10 03:19:11
【问题描述】:
我已经用 Promise
func registerWithEmail(email: String, firstName: String, lastName: String, password: String, subscribe: Bool) -> Promise<Bool>
func requestAccessTokenWithEmail(username: String, password: String) -> Promise<String>
单独使用它们效果很好:
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)
}
还有:
firstly {
client.requestAccessTokenWithEmail("foo@gmail.com", password: "password")
}.then { accessToken -> Void in
println(accessToken)
completion(success: true)
}.catch { error -> Void in
println(error.localizedDescription)
}
但是,当我链接它们时,第二个 then 调用的令牌参数永远不会填充:
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)
}
}
如果我打破这个闭包,我无法查看accessToken 参数,只能查看外部completion 闭包。但是,如果我在 requestAccessTokenWithEmail 函数内部中断,则在调用 fulfill 时会填充 accessToken 参数。
我对 PromiseKit 很陌生,所以如果我在做一些愚蠢的事情,请告诉我。
我正在使用 PromiseKit 2.0、Swift 1.2、Xcode 6.4
【问题讨论】:
标签: ios swift promisekit