• キューの作成
(Swift2まで)
let queue1 = dispatch_queue_create("arrayQ", DISPATCH_QUEUE_SERIAL)
let queue2 = dispatch_queue_create("arrayQ", DISPATCH_QUEUE_CONCURRENT)
(Swift3以降)
let queue1 = DispatchQueue(label: "arrayQ")
let queue2= DispatchQueue(label: "arrayQ", attributes: .concurrent)

(Swift2まで)
let queue3 = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0)
let queue4 = dispatch_get_main_queue()
(Swift3以降)
let queue3 = DispatchQueue.global(qos:DispatchQoS.QoSClass.background)
let queue4= DispatchQueue.main

  • グループの作成
(Swift2まで)
let group = dispatch_group_create()
(Swift3以降)
let group = DispatchGroup()

  • グループのwait
(Swift2まで)
dispatch_group_wait(group, dispatch_time_t(DISPATCH_TIME_FOREVER))
(Swift3以降)
group.wait(wallTimeout: .distantFuture)

  • 同期処理
(Swift2まで)
dispatch_sync(queue, {() in
...
}
(Swift3以降)
queue.sync {() in
...
}

  • 非同期処理
(Swift2まで)
dispatch_async(queue, {() in
...
}
(Swift3以降)
queue.async {() in
...
}

(Swift2まで)
dispatch_barrier_async(queue, {() in
...
}
(Swift3以降)
queue.async(flags: .barrier) {() in
...
}

  • セマフォ宣言
(Swift2まで)
let semaphore:dispatch_semaphore_t
(Swift3以降)
let semaphore:DispatchSemaphore

  • セマフォの作成
(Swift2まで)
semaphore = dispatch_semaphore_create(Int)
(Swift3以降)
semaphore = DispatchSemaphore(value: Int)

  • セマフォのwait
(Swift2まで)
if (dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER) == 0) { ... }
(Swift3以降)
if (semaphore.wait(timeout:.distantFuture) == .success) { ... }

  • セマフォのsignal
(Swift2まで)
dispatch_semaphore_signal(semaphore)
(Swift3以降)
semaphore.signal()