2015-07-20 53 views
0

我有我的包裹与无极<牛逼>返回类型的API请求的2:PromiseKit 2.0:链接承诺不通过参数

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("[email protected]", 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("[email protected]", password: "password") 
    }.then { accessToken -> Void in 
     println(accessToken) 
     completion(success: true) 
    }.catch { error -> Void in 
     println(error.localizedDescription) 
} 

但是,当我链接它们时,令牌参数为s的Econd 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,1.2斯威夫特,Xcode的6.4

回答

1

的问题是第一then闭合的签名。

这是success -> Void但要success -> Promise<String>

我认为这会已经由斯威夫特的类型推断抓到,但我忘了then超载同时接受(T) -> Promise<U>(T) -> U的关闭需要。

希望当Swift修复需要在then闭包中的显式签名时,它将被自动推断出来。