PromiseKit 简介

全部文章

  • 简介
  • 基础部分
    • 快速上手
    • Promise 的常见模式
    • 常见问题
  • 进阶部分
    • 故障排除
    • 附录
  • API 说明

以下是对 PromiseKitREADME.md 的翻译。

Promises 将会简化异步编程,使我们可以专注更加重要的事情上。Promises 非常容易学习,容易掌握,而且可以使返回的结果更加的清晰,更容易阅读。你的同事将会感谢你。

UIApplication.shared.isNetworkActivityIndicatorVisible = true

let fetchImage = URLSession.shared.dataTask(.promise, with: url).compactMap{ UIImage(data: $0.data) }
let fetchLocation = CLLocationManager.requestLocation().lastValue

firstly {
    when(fulfilled: fetchImage, fetchLocation)
}.done { image, location in
    self.imageView.image = image
    self.label.text = "\(location)"
}.ensure {
    UIApplication.shared.isNetworkActivityIndicatorVisible = false
}.catch { error in
    self.show(UIAlertController(for: error), sender: self)
}

PromiseKit 考虑到任何具有 swiftc 的平台,并对其实现了 promises。在 iOS、macOS、tvOS 和 watchOS 上,它不但对 Objective-C 进行了出色的桥接,而且具有可靠的设计。在许多大众的应用中,它在使用的 pod 中位于前 100。

快速上手

在 Podfile 中添加下面内容:

use_frameworks!

target "Change Me!" do
  pod "PromiseKit", "~> 6.8"
end

文档

  • 基础部分
    • 快速上手
    • Promise 的常见模式
    • 常见问题
  • 进阶部分
    • 故障排除
    • 附录
  • API 说明

你可能感兴趣的:(PromiseKit 简介)