// submit your code for asynchronous execution on a global queue with high prioritygcd.async(.High){// your code}// or with main threadgcd.async(.Main){// your code}gcd.async(.Default){// your codegcd.async(.Main){// code run on main thread}}// with your custom queueletmyQueue=GCDQueue(serial:"myQueue")gcd.async(.Custom(myQueue)){// your code}// run with delaygcd.async(.Background,delay:5.0){// your code}// sync codegcd.sync(.Main){// your code}// applygcd.apply(.Default,10){indexin// your code}// oncevaronceToken:GCDOnce=0gcd.once(&onceToken){// your code}
- manage group of block with GCDGroup
123456789101112131415
// create groupletgroup=GCDGroup()// you can add async code to groupgroup.async(.Defaul){// your code}// you can set notify for this groupgroup.notify(.Main){// your code}// or wait synchronously for block in group to complete and timeout is 10 secondsgroup.wait(10)
- create your custom queue with CGDQueue
123456789101112131415
// create a serial queueletserialQueue=GCDQueue(serial:"mySerialQueue")// create a concurrent queueletconcurrentQueue=GCDQueue(concurrent:"myConcurrentQueue")// you can submit async barrier to queuemyQueue.asyncBarrier{// your code}// or sync codemyQueue.syncBarrier{// your code}