Swift PromiseKitPromoises 模式库

联合创作 · 2023-09-28 17:26

Swift PromiseKit 是为 iOS 上实现的一个 Promoises 模式库,使用 Swift 编写。

示例代码:

CLLocationManager.promise().catch {
    // If location cannot be determined, default to Chicago
    return CLLocation(latitude: 41.89, longitude: -87.63)
}.then {
    let (lat, lon) = ($0.coordinate.latitude, $0.coordinate.longitude)
    return NSURLConnection.GET("http://user.net/\(lat)/\(lon)")
}.then { user in
    let alert = UIAlertView()
    alert.title = "Hi " + user["name"]
    alert.addButtonWithTitle("Bye")
    alert.addButtonWithTitle("Hi")
    return alert.promise()
}.then { tappedButtonIndex -> Promise<Void>? in
    if tappedButtonIndex == 0 {
        return nil
    }
    let vc = HelloViewController()
    return self.promiseViewController(vc).then { (modallyPresentedResult:String) -> Void in
        //…
    }
}.catch { error in
    //…
}
浏览 6
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报