Concurrency

suggest change

Introduction

Related topic: Grand Central Dispatch

Syntax

Parameters

queue | The queue that the code in the dispatch block will run in. A queue is like (but not exactly the same as) a thread; code in different queues can run in parallel. Use dispatch_get_main_queue to get the queue for the main thread To create a new queue, which in turn creates a new thread, use dispatch_queue_create("QUEUE_NAME", DISPATCH_QUEUE_CONCURRENT). The first parameter is the name of the queue, which is displayed in the debugger if you pause while the block is still running. The second parameter doesn’t matter unless you want to use the same queue for multiple dispatch_async or dispatch_sync calls. It describes what happens when another block is put on the same queue; DISPATCH_QUEUE_CONCURRENT will cause both blocks to run at the same time, while DISPATCH_QUEUE_SERIAL will make the second block wait for the first block to finish | —– | —– | block | Code in this block will run in the queue queue; put code you want to run on the separate queue here. A helpful tip: If you’re writing this in Xcode and the block argument has the blue outline around it, double click on the argument and Xcode will automatically make an empty block (this applies to all block arguments in any function or method) |

Remarks

Whenever you do something on a separate thread, which happens when using queues, it’s important to maintain thread safety. Some methods, in particular ones for UIViews, may not work and/or crash on threads other than main thread. Also, make sure not to change anything (variables, properties, etc.) that is also being used on the main thread, unless you are accounting for this change

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Concurrency:
* Concurrency

Table Of Contents
12 UIView
15 UIColor
20 Concurrency
26 UIImage
28 CALayer
30 NSDate
40 iBeacon
49 NSTimer
79 NSURL
87 AWS SDK
96 NSData
101 Segues
104 EventKit
105 NSBundle
106 SiriKit
111 StoreKit
117 3D Touch
119 Keychain
122 Block
141 AirDrop
144 UISlider
145 Carthage
146 HealthKit
151 plist
157 MVVM
164 UIPhoenix
166 Simulator
168 NSArray
169 OpenGL
175 Core Data
179 MyLayout
180 UIFont
189 Security
200 Codable