发布 2.0.4

发布 2.0.4

测试已测试
语言 SwiftSwift
许可证 MIT
发布最后发布2017年11月
SwiftSwift 版本3.0
SPM支持 SPM

JARM 维护。



发布 2.0.4

  • João Mourato 和 Gabriel Peart

Dispatch

## 构建状态
分支 状态
master Bunch Status
develop Bunch Status

发布

Swift 3.0
Platforms
License

Carthage compatible
Podspec

codebeat badge
codecov

注意

发布需要 Swift 3.0。对于 Swift 2.3 使用版本 1.0.0,对于 Swift 2.2 使用版本 0.9.8。

安装

CocoaPods

发布通过 CocoaPods 提供。要安装
它,只需将以下行添加到 Podfile 中

pod 'Dispatch'

Carthage


Carthage 是一个去中心化的依赖管理器,它构建您的依赖并提供二进制框架。

您可以使用以下命令使用 Homebrew 安装 Carthage

$ brew update
$ brew install carthage

要将发布集成到您的 Xcode 项目中,使用 Carthage,在您的 Cartfile 中指定它

github "Swiftification/Dispatch"

运行 carthage update 以获取发布库并将其拖入您的 Xcode 项目。

然后只需

import DispatchFramework

并且您的准备工作就绪了!

手动

  1. 下载并将 Dispatch.swift 放置到项目中任何您喜欢的地方。
  2. 就是这样。

使用方法

基本

Dispatch.async(dispatch_get_main_queue()) {
  //Code to be run on the main thread
}
或使用发布队列枚举提供的助手
Dispatch.async(Queue.main) {
  //Code to be run on the main thread
}
或使用重载方法在主线程上运行
Dispatch.async {
  //Code to be run on the main thread
}

发布类型

异步

Dispatch.async(Queue.main) {
  //Code to be run on the main thread
}

同步

let someCustomQueue = dispatch_queue_create("custom.queue.dispatch", DISPATCH_QUEUE_CONCURRENT)
Dispatch.sync(someCustomQueue) {
  //Code to be synchronously on someCustomQueue
}

之后

Dispatch.after(1.0, queue: Queue.main) {
  //Code to be run on the main thread after 1 second
}
或使用重载方法在主线程上运行
Dispatch.after(1.0) {
  //Code to be run on the main thread after 1 second
}

一次

let token : dispatch_once_t
Dispatch.once(&token) {
  //Code to be run only once in App lifetime
}

队列助手

主队列

let mainQueue = Queue.main 

自定义队列

let customConcurrentQueue = Queue.custom("custom.concurrent.queue.dispatch", Queue.Atribute.concurrent)
let customSerialQueue = Queue.custom("custom.serial.queue.dispatch", Queue.Atribute.serial)

全局队列

let priority = 0 // or you use one of the Global priorities (ex: Queue.Priority.UserInteractive)
let globalQueue = Queue.global(priority)

// For comodity there are helpers for getting the Global queues

let globalUserInteractiveQueue = Queue.globalUserInteractive
let globalUserInitiatedQueue = Queue.globalUserInitiated
let globalUtilityQueue = Queue.globalUtility
let globalBackgroundQueue = Queue.globalBackground

待办事项

  • Carthage 兼容
  • 链式方法
  • Travis CI
  • 单元测试
  • 更多示例

通信

  • 如果您 发现一个错误,请打开一个问题。
  • 如果您 有一个功能请求,请打开一个问题。
  • 如果您 想要贡献,提交一个请求。

作者

许可证

发布在 MIT 许可下。有关更多信息,请参阅 LICENSE 文件。