OperationQueue.main vs DispatchQueue.main

For details on the differences between the two types of queue, see Lion’s answer.

Both approaches will work. However, NSOperation is mostly needed when more advanced scheduling (including dependencies, canceling, etc.) is required. So in this case, a simple

DispatchQueue.main.async { /* do work */ }

will be just fine. That would be equivalent to

dispatch_async(dispatch_get_main_queue(), ^{ /* do work */ });

in Objective-C, which is also how I would do it in that language.

Leave a Comment

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