分支 | 状态 |
---|---|
master | |
develop |
发布需要 Swift 3.0。对于 Swift 2.3 使用版本 1.0.0,对于 Swift 2.2 使用版本 0.9.8。
发布通过 CocoaPods 提供。要安装
它,只需将以下行添加到 Podfile 中
pod 'Dispatch'
Carthage 是一个去中心化的依赖管理器,它构建您的依赖并提供二进制框架。
您可以使用以下命令使用 Homebrew 安装 Carthage
$ brew update
$ brew install carthage
要将发布集成到您的 Xcode 项目中,使用 Carthage,在您的 Cartfile
中指定它
github "Swiftification/Dispatch"
运行 carthage update
以获取发布库并将其拖入您的 Xcode 项目。
然后只需
import DispatchFramework
并且您的准备工作就绪了!
Dispatch.swift
放置到项目中任何您喜欢的地方。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
João Mourato,[email protected]
Gabriel Peart
发布在 MIT 许可下。有关更多信息,请参阅 LICENSE 文件。