wm.p1us wm.p1us - 1 year ago 111
Swift Question

Nothing prints out in the console in command line tool Xcode

Nothing prints out in the console in command line tool Xcode when I run the following code:

import Foundation

class A {
var someValue = 0

let concurrentQueue = dispatch_queue_create("queue_for_property", DISPATCH_QUEUE_CONCURRENT)

func increaseValueBy1000() {
dispatch_barrier_async(concurrentQueue) {
for _ in 0 ..< 1000 {
let v = self.someValue + 1
self.someValue = v

let instance1 = A()

dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0)) {


I don't see any print statement in the console.
If I remove barrier line works pretty fine.
What I do wrong in this case why my barriers don't allow to print?

Answer Source

Applications – such has command-line programs – which do not already have a "run loop" have to call


in order to use GCD. From the documentation:

This function "parks" the main thread and waits for blocks to be submitted to the main queue. Applications that call UIApplicationMain (iOS), NSApplicationMain (Mac OS X), or CFRunLoopRun on the main thread must not call dispatch_main.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download