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 … Read more

How to cancel NSBlockOperation

Doh. Dear future googlers: of course operation is nil when copied by the block, but it doesn’t have to be copied. It can be qualified with __block like so: //THIS MIGHT LEAK! See the update below. __block NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{ while( ! [operation isCancelled]){ //do something… } }]; UPDATE: Upon further meditation, it … Read more

Subclassing NSOperation to be concurrent and cancellable

Okay, so as I understand it, you have two questions: Do you need the performSelectorOnMainThread: segment that appears in comments in your code? What does that code do? Why is the _isCancelled flag is not modified when you call cancelAllOperations on the NSOperationQueue that contains this operation? Let’s deal with these in order. I’m going … Read more

How do I use NSOperationQueue with NSURLSession?

Your intuition here is correct. If issuing many requests, having an NSOperationQueue with maxConcurrentOperationCount of 4 or 5 can be very useful. In the absence of that, if you issue many requests (say, 50 large images), you can suffer timeout problems when working on a slow network connection (e.g. some cellular connections). Operation queues have … Read more

NSOperation and NSOperationQueue working thread vs main thread

My question is whether the database write operation occur in main thread or in a background thread? If you create an NSOperationQueue from scratch as in: NSOperationQueue *myQueue = [[NSOperationQueue alloc] init]; It will be in a background thread: Operation queues usually provide the threads used to run their operations. In OS X v10.6 and … Read more

NSOperation vs Grand Central Dispatch

GCD is a low-level C-based API that enables very simple use of a task-based concurrency model. NSOperation and NSOperationQueue are Objective-C classes that do a similar thing. NSOperation was introduced first, but as of 10.5 and iOS 2, NSOperationQueue and friends are internally implemented using GCD. In general, you should use the highest level of … Read more

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