GCD
Grand Central Dispatch (GCD)是Apple开发的一个多核编程的较新的解决方法。它主要用于优化应用程序以支持多核处理器以及其他对称多处理系统。它是一个在线程池模式的基础上执行的并行任务。在Mac OS X 10.6雪豹中首次推出,也可在IOS 4及以上版本使用。
GCD 中两个重要重要概念 —— 队列 & 任务
-
GCD 头文件改变
import Dispatch.base // 没有实质性内容
import Dispatch.block // 没有实质性内容
import Dispatch.data // 没有实质性内容
import Dispatch.group
import Dispatch.io
import Dispatch.object
import Dispatch.once // 没有实质性内容
import Dispatch.queue
import Dispatch.semaphore
import Dispatch.source
import Dispatch.time
import Dispatch
import os_object
// 在 swift3.0 中新加的, OS_object 继承自 NSObject
import os_object
open class OS_object : NSObject {
}
// 获取 GCD 版本信息
public var DISPATCH_API_VERSION: Int32 { get }
/// dispatch_group
extension DispatchGroup {
public func notify(qos: DispatchQoS = default, flags: DispatchWorkItemFlags = default, queue: DispatchQueue, execute work: @escaping @convention(block) () -> ())
public func notify(queue: DispatchQueue, work: DispatchWorkItem)
public func wait()
public func wait(timeout: DispatchTime) -> DispatchTimeoutResult
public func wait(wallTimeout timeout: DispatchWallTime) -> DispatchTimeoutResult
}
/// dispatch_semaphore
extension DispatchSemaphore {
public func signal() -> Int
public func wait()
public func wait(timeout: DispatchTime) -> DispatchTimeoutResult
public func wait(wallTimeout: DispatchWallTime) -> DispatchTimeoutResult
}
extension DispatchSourceMemoryPressure {
public var data: DispatchSource.MemoryPressureEvent { get }
public var mask: DispatchSource.MemoryPressureEvent { get }
}
extension DispatchSource {
public struct MachSendEvent : OptionSet, RawRepresentable {
/// The corresponding value of the raw type.
///
/// A new instance initialized with `rawValue` will be equivalent to this
/// instance. For example:
///
/// enum PaperSize: String {
/// case A4, A5, Letter, Legal
/// }
///
/// let selectedSize = PaperSize.Letter
/// print(selectedSize.rawValue)
/// // Prints "Letter"
///
/// print(selectedSize == PaperSize(rawValue: selectedSize.rawValue)!)
/// // Prints "true"
public let rawValue: UInt
/// Creates a new option set from the given raw value.
///
/// This initializer always succeeds, even if the value passed as `rawValue`
/// exceeds the static properties declared as part of the option set. This
/// example creates an instance of `ShippingOptions` with a raw value beyond
/// the highest element, with a bit mask that effectively contains all the
/// declared static members.
///
/// let extraOptions = ShippingOptions(rawValue: 255)
/// print(extraOptions.isStrictSuperset(of: .all))
/// // Prints "true"
///
/// - Parameter rawValue: The raw value of the option set to create. Each bit
/// of `rawValue` potentially represents an element of the option set,
/// though raw values may include bits that are not defined as distinct
/// values of the `OptionSet` type.
public init(rawValue: UInt)
public static let dead: DispatchSource.MachSendEvent
}
public struct MemoryPressureEvent : OptionSet, RawRepresentable {
public let rawValue: UInt
public init(rawValue: UInt)
public static let normal: DispatchSource.MemoryPressureEvent
public static let warning: DispatchSource.MemoryPressureEvent
public static let critical: DispatchSource.MemoryPressureEvent
public static let all: DispatchSource.MemoryPressureEvent
}
public struct ProcessEvent : OptionSet, RawRepresentable {
public let rawValue: UInt
public init(rawValue: UInt)
public static let exit: DispatchSource.ProcessEvent
public static let fork: DispatchSource.ProcessEvent
public static let exec: DispatchSource.ProcessEvent
public static let signal: DispatchSource.ProcessEvent
public static let all: DispatchSource.ProcessEvent
}
public struct TimerFlags : OptionSet, RawRepresentable {
public let rawValue: UInt
public init(rawValue: UInt)
public static let strict: DispatchSource.TimerFlags
}
public struct FileSystemEvent : OptionSet, RawRepresentable {
public let rawValue: UInt
public init(rawValue: UInt)
public static let delete: DispatchSource.FileSystemEvent
public static let write: DispatchSource.FileSystemEvent
public static let extend: DispatchSource.FileSystemEvent
public static let attrib: DispatchSource.FileSystemEvent
public static let link: DispatchSource.FileSystemEvent
public static let rename: DispatchSource.FileSystemEvent
public static let revoke: DispatchSource.FileSystemEvent
public static let funlock: DispatchSource.FileSystemEvent
public static let all: DispatchSource.FileSystemEvent
}
public class func makeMachSendSource(port: mach_port_t, eventMask: DispatchSource.MachSendEvent, queue: DispatchQueue? = default) -> DispatchSourceMachSend
public class func makeMachReceiveSource(port: mach_port_t, queue: DispatchQueue? = default) -> DispatchSourceMachReceive
public class func makeMemoryPressureSource(eventMask: DispatchSource.MemoryPressureEvent, queue: DispatchQueue? = default) -> DispatchSourceMemoryPressure
public class func makeProcessSource(identifier: pid_t, eventMask: DispatchSource.ProcessEvent, queue: DispatchQueue? = default) -> DispatchSourceProcess
public class func makeReadSource(fileDescriptor: Int32, queue: DispatchQueue? = default) -> DispatchSourceRead
public class func makeSignalSource(signal: Int32, queue: DispatchQueue? = default) -> DispatchSourceSignal
public class func makeTimerSource(flags: DispatchSource.TimerFlags = default, queue: DispatchQueue? = default) -> DispatchSourceTimer
public class func makeUserDataAddSource(queue: DispatchQueue? = default) -> DispatchSourceUserDataAdd
public class func makeUserDataOrSource(queue: DispatchQueue? = default) -> DispatchSourceUserDataOr
public class func makeFileSystemObjectSource(fileDescriptor: Int32, eventMask: DispatchSource.FileSystemEvent, queue: DispatchQueue? = default) -> DispatchSourceFileSystemObject
public class func makeWriteSource(fileDescriptor: Int32, queue: DispatchQueue? = default) -> DispatchSourceWrite
}
extension DispatchSourceProcess {
public var handle: pid_t { get }
public var data: DispatchSource.ProcessEvent { get }
public var mask: DispatchSource.ProcessEvent { get }
}
extension DispatchSourceUserDataAdd {
public func add(data: UInt)
}
extension DispatchSourceMachReceive {
public var handle: mach_port_t { get }
}
extension DispatchSourceFileSystemObject {
public var handle: Int32 { get }
public var data: DispatchSource.FileSystemEvent { get }
public var mask: DispatchSource.FileSystemEvent { get }
}
extension DispatchSourceUserDataOr {
public func or(data: UInt)
}
extension DispatchQueue {
public struct Attributes : OptionSet {
public let rawValue: UInt64
public init(rawValue: UInt64)
public static let concurrent: DispatchQueue.Attributes
public static let initiallyInactive: DispatchQueue.Attributes
}
public enum GlobalQueuePriority {
@available(OSX, deprecated: 10.10, message: "Use qos attributes instead")
@available(iOS, deprecated: 8.0, message: "Use qos attributes instead")
@available(tvOS, deprecated, message: "Use qos attributes instead")
@available(watchOS, deprecated, message: "Use qos attributes instead")
case high
@available(OSX, deprecated: 10.10, message: "Use qos attributes instead")
@available(iOS, deprecated: 8.0, message: "Use qos attributes instead")
@available(tvOS, deprecated, message: "Use qos attributes instead")
@available(watchOS, deprecated, message: "Use qos attributes instead")
case `default`
@available(OSX, deprecated: 10.10, message: "Use qos attributes instead")
@available(iOS, deprecated: 8.0, message: "Use qos attributes instead")
@available(tvOS, deprecated, message: "Use qos attributes instead")
@available(watchOS, deprecated, message: "Use qos attributes instead")
case low
@available(OSX, deprecated: 10.10, message: "Use qos attributes instead")
@available(iOS, deprecated: 8.0, message: "Use qos attributes instead")
@available(tvOS, deprecated, message: "Use qos attributes instead")
@available(watchOS, deprecated, message: "Use qos attributes instead")
case background
}
public enum AutoreleaseFrequency {
case inherit
case workItem
case never
}
public class func concurrentPerform(iterations: Int, execute work: (Int) -> Swift.Void)
public class var main: DispatchQueue { get }
@available(OSX, deprecated: 10.10)
@available(iOS, deprecated: 8.0)
@available(tvOS, deprecated)
@available(watchOS, deprecated)
public class func global(priority: DispatchQueue.GlobalQueuePriority) -> DispatchQueue
public class func global(qos: DispatchQoS.QoSClass = default) -> DispatchQueue
public class func getSpecific<T>(key: DispatchSpecificKey<T>) -> T?
public convenience init(label: String, qos: DispatchQoS = default, attributes: DispatchQueue.Attributes = default, autoreleaseFrequency: DispatchQueue.AutoreleaseFrequency = default, target: DispatchQueue? = default)
public var label: String { get }
public func sync(execute workItem: DispatchWorkItem)
public func async(execute workItem: DispatchWorkItem)
public func async(group: DispatchGroup, execute workItem: DispatchWorkItem)
public func async(group: DispatchGroup? = default, qos: DispatchQoS = default, flags: DispatchWorkItemFlags = default, execute work: @escaping @convention(block) () -> Swift.Void)
public func sync<T>(execute work: () throws -> T) rethrows -> T
public func sync<T>(flags: DispatchWorkItemFlags, execute work: () throws -> T) rethrows -> T
public func asyncAfter(deadline: DispatchTime, qos: DispatchQoS = default, flags: DispatchWorkItemFlags = default, execute work: @escaping @convention(block) () -> Swift.Void)
public func asyncAfter(wallDeadline: DispatchWallTime, qos: DispatchQoS = default, flags: DispatchWorkItemFlags = default, execute work: @escaping @convention(block) () -> Swift.Void)
public func asyncAfter(deadline: DispatchTime, execute: DispatchWorkItem)
public func asyncAfter(wallDeadline: DispatchWallTime, execute: DispatchWorkItem)
public var qos: DispatchQoS { get }
public func getSpecific<T>(key: DispatchSpecificKey<T>) -> T?
public func setSpecific<T>(key: DispatchSpecificKey<T>, value: T)
}
extension DispatchSourceProtocol {
public typealias DispatchSourceHandler = @convention(block) () -> Swift.Void
public func setEventHandler(qos: DispatchQoS = default, flags: DispatchWorkItemFlags = default, handler: DispatchSourceProtocol.DispatchSourceHandler?)
public func setEventHandler(handler: DispatchWorkItem)
public func setCancelHandler(qos: DispatchQoS = default, flags: DispatchWorkItemFlags = default, handler: DispatchSourceProtocol.DispatchSourceHandler?)
public func setCancelHandler(handler: DispatchWorkItem)
public func setRegistrationHandler(qos: DispatchQoS = default, flags: DispatchWorkItemFlags = default, handler: DispatchSourceProtocol.DispatchSourceHandler?)
public func setRegistrationHandler(handler: DispatchWorkItem)
public func activate()
public func cancel()
public func resume()
public func suspend()
public var handle: UInt { get }
public var mask: UInt { get }
public var data: UInt { get }
public var isCancelled: Bool { get }
}
extension DispatchSourceMachSend {
public var handle: mach_port_t { get }
public var data: DispatchSource.MachSendEvent { get }
public var mask: DispatchSource.MachSendEvent { get }
}
extension DispatchIO {
public enum StreamType : UInt {
case stream
case random
}
public struct CloseFlags : OptionSet, RawRepresentable {
public let rawValue: UInt
public init(rawValue: UInt)
public static let stop: DispatchIO.CloseFlags
}
public struct IntervalFlags : OptionSet, RawRepresentable {
public let rawValue: UInt
public init(rawValue: UInt)
public init(nilLiteral: ())
public static let strictInterval: DispatchIO.IntervalFlags
}
public class func read(fromFileDescriptor: Int32, maxLength: Int, runningHandlerOn queue: DispatchQueue, handler: @escaping (DispatchData, Int32) -> Swift.Void)
public class func write(toFileDescriptor: Int32, data: DispatchData, runningHandlerOn queue: DispatchQueue, handler: @escaping (DispatchData?, Int32) -> Swift.Void)
public convenience init(type: DispatchIO.StreamType, fileDescriptor: Int32, queue: DispatchQueue, cleanupHandler: @escaping (Int32) -> Swift.Void)
public convenience init(type: DispatchIO.StreamType, path: UnsafePointer<Int8>, oflag: Int32, mode: mode_t, queue: DispatchQueue, cleanupHandler: @escaping (Int32) -> Swift.Void)
public convenience init(type: DispatchIO.StreamType, io: DispatchIO, queue: DispatchQueue, cleanupHandler: @escaping (Int32) -> Swift.Void)
public func read(offset: off_t, length: Int, queue: DispatchQueue, ioHandler: @escaping (Bool, DispatchData?, Int32) -> Swift.Void)
public func write(offset: off_t, data: DispatchData, queue: DispatchQueue, ioHandler: @escaping (Bool, DispatchData?, Int32) -> Swift.Void)
public func setInterval(interval: DispatchTimeInterval, flags: DispatchIO.IntervalFlags = default)
public func close(flags: DispatchIO.CloseFlags = default)
}
public func +(time: DispatchWallTime, seconds: Double) -> DispatchWallTime
public func +(time: DispatchTime, interval: DispatchTimeInterval) -> DispatchTime
public func +(time: DispatchTime, seconds: Double) -> DispatchTime
public func +(time: DispatchWallTime, interval: DispatchTimeInterval) -> DispatchWallTime
public func -(time: DispatchTime, interval: DispatchTimeInterval) -> DispatchTime
public func -(time: DispatchTime, seconds: Double) -> DispatchTime
public func -(time: DispatchWallTime, interval: DispatchTimeInterval) -> DispatchWallTime
public func -(time: DispatchWallTime, seconds: Double) -> DispatchWallTime
public func <(a: DispatchTime, b: DispatchTime) -> Bool
public func <(a: DispatchWallTime, b: DispatchWallTime) -> Bool
public func ==(a: DispatchTime, b: DispatchTime) -> Bool
public func ==(a: DispatchQoS, b: DispatchQoS) -> Bool
public func ==(a: DispatchWallTime, b: DispatchWallTime) -> Bool
public struct DispatchData : RandomAccessCollection {
/// A type that provides the collection's iteration interface and
/// encapsulates its iteration state.
///
/// By default, a collection conforms to the `Sequence` protocol by
/// supplying a `IndexingIterator` as its associated `Iterator`
/// type.
public typealias Iterator = DispatchDataIterator
/// A type that represents a position in the collection.
///
/// Valid indices consist of the position of every element and a
/// "past the end" position that's not valid for use as a subscript
/// argument.
///
/// - SeeAlso: endIndex
public typealias Index = Int
/// A type that can represent the indices that are valid for subscripting the
/// collection, in ascending order.
public typealias Indices = DefaultRandomAccessIndices<DispatchData>
public static let empty: DispatchData
public enum Deallocator {
/// Use `free`
case free
/// Use `munmap`
case unmap
/// A custom deallocator
case custom(DispatchQueue?, @convention(block) () -> Swift.Void)
}
/// Initialize a `Data` with copied memory content.
///
/// - parameter bytes: A pointer to the memory. It will be copied.
/// - parameter count: The number of bytes to copy.
public init(bytes buffer: UnsafeBufferPointer<UInt8>)
/// Initialize a `Data` without copying the bytes.
///
/// - parameter bytes: A pointer to the bytes.
/// - parameter count: The size of the bytes.
/// - parameter deallocator: Specifies the mechanism to free the indicated buffer.
public init(bytesNoCopy bytes: UnsafeBufferPointer<UInt8>, deallocator: DispatchData.Deallocator = default)
/// The number of elements in the collection.
///
/// - Complexity: O(1) if the collection conforms to
/// `RandomAccessCollection`; otherwise, O(*n*), where *n* is the length
/// of the collection.
public var count: Int { get }
public func withUnsafeBytes<Result, ContentType>(body: (UnsafePointer<ContentType>) throws -> Result) rethrows -> Result
public func enumerateBytes(block: (UnsafeBufferPointer<UInt8>, Int, inout Bool) -> Swift.Void)
/// Append bytes to the data.
///
/// - parameter bytes: A pointer to the bytes to copy in to the data.
/// - parameter count: The number of bytes to copy.
public mutating func append(_ bytes: UnsafePointer<UInt8>, count: Int)
/// Append data to the data.
///
/// - parameter data: The data to append to this data.
public mutating func append(_ other: DispatchData)
/// Append a buffer of bytes to the data.
///
/// - parameter buffer: The buffer of bytes to append. The size is calculated from `SourceType` and `buffer.count`.
public mutating func append<SourceType>(_ buffer: UnsafeBufferPointer<SourceType>)
/// Copy the contents of the data to a pointer.
///
/// - parameter pointer: A pointer to the buffer you wish to copy the bytes into.
/// - parameter count: The number of bytes to copy.
/// - warning: This method does not verify that the contents at pointer have enough space to hold `count` bytes.
public func copyBytes(to pointer: UnsafeMutablePointer<UInt8>, count: Int)
/// Copy a subset of the contents of the data to a pointer.
///
/// - parameter pointer: A pointer to the buffer you wish to copy the bytes into.
/// - parameter range: The range in the `Data` to copy.
/// - warning: This method does not verify that the contents at pointer have enough space to hold the required number of bytes.
public func copyBytes(to pointer: UnsafeMutablePointer<UInt8>, from range: CountableRange<DispatchData.Index>)
/// Copy the contents of the data into a buffer.
///
/// This function copies the bytes in `range` from the data into the buffer. If the count of the `range` is greater than `MemoryLayout<DestinationType>.stride * buffer.count` then the first N bytes will be copied into the buffer.
/// - precondition: The range must be within the bounds of the data. Otherwise `fatalError` is called.
/// - parameter buffer: A buffer to copy the data into.
/// - parameter range: A range in the data to copy into the buffer. If the range is empty, this function will return 0 without copying anything. If the range is nil, as much data as will fit into `buffer` is copied.
/// - returns: Number of bytes copied into the destination buffer.
public func copyBytes<DestinationType>(to buffer: UnsafeMutableBufferPointer<DestinationType>, from range: CountableRange<DispatchData.Index>? = default) -> Int
/// Sets or returns the byte at the specified index.
public subscript(index: DispatchData.Index) -> UInt8 { get }
/// Accesses the subsequence bounded by the given range.
///
/// - Parameter bounds: A range of the collection's indices. The upper and
/// lower bounds of the `bounds` range must be valid indices of the
/// collection.
public subscript(bounds: Range<Int>) -> RandomAccessSlice<DispatchData> { get }
/// Return a new copy of the data in a specified range.
///
/// - parameter range: The range to copy.
public func subdata(in range: CountableRange<DispatchData.Index>) -> DispatchData
public func region(location: Int) -> (data: DispatchData, offset: Int)
/// The position of the first element in a nonempty collection.
///
/// If the collection is empty, `startIndex` is equal to `endIndex`.
public var startIndex: DispatchData.Index { get }
/// The collection's "past the end" position---that is, the position one
/// greater than the last valid subscript argument.
///
/// When you need a range that includes the last element of a collection, use
/// the half-open range operator (`..<`) with `endIndex`. The `..<` operator
/// creates a range that doesn't include the upper bound, so it's always
/// safe to use with `endIndex`. For example:
///
/// let numbers = [10, 20, 30, 40, 50]
/// if let index = numbers.index(of: 30) {
/// print(numbers[index ..< numbers.endIndex])
/// }
/// // Prints "[30, 40, 50]"
///
/// If the collection is empty, `endIndex` is equal to `startIndex`.
public var endIndex: DispatchData.Index { get }
/// Returns the position immediately before the given index.
///
/// - Parameter i: A valid index of the collection. `i` must be greater than
/// `startIndex`.
/// - Returns: The index value immediately before `i`.
public func index(before i: DispatchData.Index) -> DispatchData.Index
/// Returns the position immediately after the given index.
///
/// - Parameter i: A valid index of the collection. `i` must be less than
/// `endIndex`.
/// - Returns: The index value immediately after `i`.
public func index(after i: DispatchData.Index) -> DispatchData.Index
/// An iterator over the contents of the data.
///
/// The iterator will increment byte-by-byte.
public func makeIterator() -> DispatchData.Iterator
}
public struct DispatchDataIterator : IteratorProtocol, Sequence {
/// Advance to the next element and return it, or `nil` if no next
/// element exists.
public mutating func next() -> DispatchData._Element?
}
/// dispatch_assert
public enum DispatchPredicate {
case onQueue(DispatchQueue)
case onQueueAsBarrier(DispatchQueue)
case notOnQueue(DispatchQueue)
}
/// qos_class_t
public struct DispatchQoS : Equatable {
public let qosClass: DispatchQoS.QoSClass
public let relativePriority: Int
public static let background: DispatchQoS
public static let utility: DispatchQoS
public static let `default`: DispatchQoS
public static let userInitiated: DispatchQoS
public static let userInteractive: DispatchQoS
public static let unspecified: DispatchQoS
public enum QoSClass {
case background
case utility
case `default`
case userInitiated
case userInteractive
case unspecified
public init?(rawValue: qos_class_t)
public var rawValue: qos_class_t { get }
}
public init(qosClass: DispatchQoS.QoSClass, relativePriority: Int)
}
final public class DispatchSpecificKey<T> {
public init()
}
public struct DispatchTime : Comparable {
public let rawValue: dispatch_time_t
public static func now() -> DispatchTime
public static let distantFuture: DispatchTime
/// Creates a `DispatchTime` relative to the system clock that
/// ticks since boot.
///
/// - Parameters:
/// - uptimeNanoseconds: The number of nanoseconds since boot, excluding
/// time the system spent asleep
/// - Returns: A new `DispatchTime`
/// - Discussion: This clock is the same as the value returned by
/// `mach_absolute_time` when converted into nanoseconds.
public init(uptimeNanoseconds: UInt64)
public var uptimeNanoseconds: UInt64 { get }
}
public enum DispatchTimeInterval {
case seconds(Int)
case milliseconds(Int)
case microseconds(Int)
case nanoseconds(Int)
}
///
public enum DispatchTimeoutResult {
case success
case timedOut
}
public struct DispatchWallTime : Comparable {
public let rawValue: dispatch_time_t
public static func now() -> DispatchWallTime
public static let distantFuture: DispatchWallTime
public init(timespec: timespec)
}
public class DispatchWorkItem {
public init(qos: DispatchQoS = default, flags: DispatchWorkItemFlags = default, block: @escaping @convention(block) () -> ())
public func perform()
public func wait()
public func wait(timeout: DispatchTime) -> DispatchTimeoutResult
public func wait(wallTimeout: DispatchWallTime) -> DispatchTimeoutResult
public func notify(qos: DispatchQoS = default, flags: DispatchWorkItemFlags = default, queue: DispatchQueue, execute: @escaping @convention(block) () -> Swift.Void)
public func notify(queue: DispatchQueue, execute: DispatchWorkItem)
public func cancel()
public var isCancelled: Bool { get }
}
public struct DispatchWorkItemFlags : OptionSet, RawRepresentable {
/// The corresponding value of the raw type.
///
/// A new instance initialized with `rawValue` will be equivalent to this
/// instance. For example:
///
/// enum PaperSize: String {
/// case A4, A5, Letter, Legal
/// }
///
/// let selectedSize = PaperSize.Letter
/// print(selectedSize.rawValue)
/// // Prints "Letter"
///
/// print(selectedSize == PaperSize(rawValue: selectedSize.rawValue)!)
/// // Prints "true"
public let rawValue: UInt
/// Creates a new option set from the given raw value.
///
/// This initializer always succeeds, even if the value passed as `rawValue`
/// exceeds the static properties declared as part of the option set. This
/// example creates an instance of `ShippingOptions` with a raw value beyond
/// the highest element, with a bit mask that effectively contains all the
/// declared static members.
///
/// let extraOptions = ShippingOptions(rawValue: 255)
/// print(extraOptions.isStrictSuperset(of: .all))
/// // Prints "true"
///
/// - Parameter rawValue: The raw value of the option set to create. Each bit
/// of `rawValue` potentially represents an element of the option set,
/// though raw values may include bits that are not defined as distinct
/// values of the `OptionSet` type.
public init(rawValue: UInt)
public static let barrier: DispatchWorkItemFlags
public static let detached: DispatchWorkItemFlags
public static let assignCurrentContext: DispatchWorkItemFlags
public static let noQoS: DispatchWorkItemFlags
public static let inheritQoS: DispatchWorkItemFlags
public static let enforceQoS: DispatchWorkItemFlags
}
public func dispatchPrecondition(condition: @autoclosure () -> DispatchPredicate)
定时器
extension DispatchSourceTimer {
public func scheduleOneshot(deadline: DispatchTime, leeway: DispatchTimeInterval = default)
public func scheduleOneshot(wallDeadline: DispatchWallTime, leeway: DispatchTimeInterval = default)
public func scheduleRepeating(deadline: DispatchTime, interval: DispatchTimeInterval, leeway: DispatchTimeInterval = default)
public func scheduleRepeating(deadline: DispatchTime, interval: Double, leeway: DispatchTimeInterval = default)
public func scheduleRepeating(wallDeadline: DispatchWallTime, interval: DispatchTimeInterval, leeway: DispatchTimeInterval = default)
public func scheduleRepeating(wallDeadline: DispatchWallTime, interval: Double, leeway: DispatchTimeInterval = default)
}