2015-07-20 55 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閉包中的顯式簽名時,它將被自動推斷出來。