Is DispatchQueue.global(qos: .userInteractive).async same as DispatchQueue.main.async

The “quality of service” definitions are described here: https://developer.apple.com/library/content/documentation/Performance/Conceptual/EnergyGuide-iOS/PrioritizeWorkWithQoS.html It looks like the “main” thread will have a QoS class of “User-interactive”. However, just because a thread is created with a QoS of “User-interactive”, does not mean that it is the “main” thread. You can observe this in the Xcode debugger. Put a breakpoint inside … Read more

Do you need to create an NSAutoreleasePool within a block in GCD?

Does the same rule apply to a block that is placed within a Grand Central Dispatch queue and will be run on a non-main thread? That is, do you need to create an NSAutoreleasePool within each block you dispatch to anything other than the main queue? Grand central dispatch will manage an autorelease pool per … Read more

Operation Queue vs Dispatch Queue for iOS Application

OperationQueue internally uses Grand Central Dispatch and on iOS. OperationQueue gives you a lot more control over how your operations are executed. You can define dependencies between individual operations for example, which isn’t possible with plain GCD queues. It is also possible to cancel operations that have been enqueued in an OperationQueue (as far as … Read more

Alternatives to dispatch_get_current_queue() for completion blocks in iOS 6?

The pattern of “run on whatever queue the caller was on” is appealing, but ultimately not a great idea. That queue could be a low priority queue, the main queue, or some other queue with odd properties. My favorite approach to this is to say “the completion block runs on an implementation defined queue with … Read more

Difference between dispatch_async and dispatch_sync on serial queue?

Yes. Using serial queue ensure the serial execution of tasks. The only difference is that dispatch_sync only return after the block is finished whereas dispatch_async return after it is added to the queue and may not finished. for this code dispatch_async(_serialQueue, ^{ printf(“1”); }); printf(“2”); dispatch_async(_serialQueue, ^{ printf(“3”); }); printf(“4”); It may print 2413 or … Read more

Waiting until the task finishes

If you need to hide the asynchronous nature of myFunction from the caller, use DispatchGroups to achieve this. Otherwise, use a completion block. Find samples for both below. DispatchGroup Sample You can either get notified when the group’s enter() and leave() calls are balanced: func myFunction() { var a = 0 let group = DispatchGroup() … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)