SwiftPromiseKit是为iOS上实现的一个Promoises模式库,使用Swift编写。
示例代码:
CLLocatioMaager.promise().catch { // If locatio caot be determied, default to Chicago retur CLLocatio(latitude: 41.89, logitude: -87.63)}.the { let (lat, lo) = ($0.coordiate.latitude, $0.coordiate.logitude) retur NSURLCoectio.GET("https://user.et/\(lat)/\(lo)")}.the { user i let alert = UIAlertView() alert.title = "Hi " + user["ame"] alert.addButtoWithTitle("Bye") alert.addButtoWithTitle("Hi") retur alert.promise()}.the { tappedButtoIdex -> Promise<Void>? i if tappedButtoIdex == 0 { retur il } let vc = HelloViewCotroller() retur self.promiseViewCotroller(vc).the { (modallyPresetedResult:Strig) -> Void i //… }}.catch { error i //…}









评论