Get current dispatch queue?

If you are working with an NSOperationQueue, it can provide the current dispatch queue for you. NSOperationQueue has the class function [NSOperationQueue currentQueue], which returns the current queue as a NSOperationQueue object. To get the dispatch queue object you can use [NSOperationQueue currentQueue].underlyingQueue, which returns your currrent queue as a dispatch_queue_t. Swift 3: if let … Read more

DispatchQueue : Cannot be called with asCopy = NO on non-main thread

You should call all code from showAlertMessage on main queue: class func showAlertMessage(message:String, viewController: UIViewController) { DispatchQueue.main.async { let alertMessage = UIAlertController(title: “”, message: message, preferredStyle: .alert) let cancelAction = UIAlertAction(title: “Ok”, style: .cancel) alertMessage.addAction(cancelAction) viewController.present(alertMessage, animated: true, completion: nil) } }

EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0) on dispatch_semaphore_dispose

From your stack trace, EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0) occurred because dispatch_group_t was released while it was still locking (waiting for dispatch_group_leave). According to what you found, this was what happened : dispatch_group_t group was created. group‘s retain count = 1. -[self webservice:onCompletion:] captured the group. group‘s retain count = 2. dispatch_async(…., ^{ dispatch_group_wait(group, …) … }); … Read more

dispatch_get_global_queue vs dispatch_get_main_queue

The dispatch_get_global_queue (DispatchQueue.global() in Swift) gets you a background queue upon which you can dispatch background tasks that are run asynchronously (i.e. won’t block your user interface). And if you end up submitting multiple blocks to the global queues, these jobs can operate concurrently. If you have multiple blocks of code that you want to … Read more

How do you schedule a block to run on the next run loop iteration?

You might not be aware of everything that the run loop does in each iteration. (I wasn’t before I researched this answer!) As it happens, CFRunLoop is part of the open-source CoreFoundation package, so we can take a look at exactly what it entails. The run loop looks roughly like this: while (true) { Call … Read more

Grand Central Dispatch (GCD) vs. performSelector – need a better explanation

As Jacob points out, while they may appear the same, they are different things. In fact, there’s a significant difference in the way that they handle sending actions to the main thread if you’re already running on the main thread. I ran into this recently, where I had a common method that sometimes was run … Read more

Unable to access global variables in dispatch_async : “Variable is not Assignable (missing _block type specifier)” [duplicate]

You must use the __block specifier when you modify a variable inside a block, so the code you gave should look like this instead: __block NSString *textString; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, (unsigned long)NULL), ^(void) { textString = [self getTextString]; }); Blocks capture the state of the variables referenced inside their bodies, so the captured variable must be declared … Read more

Does dispatch_async(dispatch_get_main_queue(), ^{…}); wait until done?

No it doesn’t wait and the way you are doing it in that sample is not good practice. dispatch_async is always asynchronous. It’s just that you are enqueueing all the UI blocks to the same queue so the different blocks will run in sequence but parallel with your data processing code. If you want the … Read more

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