Questions tagged [nsoperationqueue]

On Mac OS X, the NSOperationQueue class regulates the execution of a set of NSOperation objects.

The NSOperationQueue class regulates the execution of a set of NSOperation () objects. After being added to a queue, an operation remains in that queue until it is explicitly canceled or finishes executing its task. Operations within the queue (but not yet executing) are themselves organized according to priority levels and inter-operation object dependencies and are executed accordingly. An application may create multiple operation queues and submit operations to any of them.

References:

1047 questions
490
votes
9 answers

NSOperation vs Grand Central Dispatch

I'm learning about concurrent programming for iOS. So far I've read about NSOperation/NSOperationQueue and GCD. What are the reasons for using NSOperationQueue over GCD and vice versa? Sounds like both GCD and NSOperationQueue abstract away the…
83
votes
6 answers

NSOperation and NSOperationQueue working thread vs main thread

I have to carry out a series of download and database write operations in my app. I am using the NSOperation and NSOperationQueue for the same. This is application scenario: Fetch all postcodes from a place. For each postcode fetch all…
Zach
  • 9,989
  • 19
  • 70
  • 107
56
votes
7 answers

How do I use NSOperationQueue with NSURLSession?

I'm trying to build a bulk image downloader, where images can be added to a queue on the fly to be downloaded, and I can find out the progress and when they're done downloading. Through my reading it seems like NSOperationQueue for the queue…
Doug Smith
  • 29,668
  • 57
  • 204
  • 388
52
votes
6 answers

Subclassing NSOperation to be concurrent and cancellable

I am unable to find good documentation about how to subclass NSOperation to be concurrent and also to support cancellation. I read the Apple docs, but I am unable to find an "official" example. Here is my source code : @synthesize isExecuting =…
thierryb
  • 3,660
  • 4
  • 42
  • 58
50
votes
4 answers

How to cancel NSBlockOperation

I have a long running loop I want to run in the background with an NSOperation. I'd like to use a block: NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{ while(/* not canceled*/){ //do something... } }]; The…
jemmons
  • 18,605
  • 8
  • 55
  • 84
50
votes
4 answers

(iOS) dispatch_async() vs. NSOperationQueue

I learned iOS programming thanks to Stanford's CS193p course (on iTunes U) as well as the iOS programming book from Big Nerd Ranch. In both of those, they recommend using dispatch_async(), dispatch_get_main_queue(), etc. to handle threading and…
Donald Burr
  • 2,281
  • 2
  • 23
  • 31
36
votes
3 answers

OperationQueue.main vs DispatchQueue.main

When you need to perform something on the main thread in the completion block of a networking task or an operation, which of these ways to get it would be the most appropriate and why?: OperationQueue.main.addOperation DispatchQueue.main.async
AppsDev
  • 12,319
  • 23
  • 93
  • 186
30
votes
2 answers

NSThread vs. NSOperationQueue vs. ??? on the iPhone

Currently I'm using NSThread to cache images in another thread. [NSThread detachNewThreadSelector:@selector(cacheImage:) toTarget:self withObject:image]; Alternately: [self performSelectorInBackground:@selector(cacheImage:)…
kubi
  • 48,104
  • 19
  • 94
  • 118
28
votes
3 answers

Default value of maxConcurrentOperationCount for NSOperationQueue

As the title suggests, what is the default value of the maxConcurrentOperationCount for NSOperationQueue? Is it set to a value of 1?
lakshmen
  • 28,346
  • 66
  • 178
  • 276
28
votes
7 answers

NSOperation - Forcing an operation to wait others dynamically

I am trying to implement an operation queue and I have the following scenario: NSOperation A NSOperation B NSOperation C NSOperation D NSOperationQueue queue I start adding A to queue. During the execution of A I need to get some data from B and I…
Rafael
  • 1,655
  • 3
  • 17
  • 25
25
votes
1 answer

How to make the NSOperationQueue serial?

I am intending to make the NSOperationQueue serial instead of concurrent. One way I know is: NSOperationQueue *globalQueue; globalQueue.maxConcurrentOperationCount =1; Is there any other way?
lakshmen
  • 28,346
  • 66
  • 178
  • 276
25
votes
1 answer

NSOperationQueue mainQueue vs performSelectorOnMainThread?

What's the difference between this: [[NSOperationQueue mainQueue] addOperationWithBlock:^{ [self doSomthing:object]; }]; and this: [self performSelectorOnMainThread:@selector(doSomething:) withObject:object waitUntilDone:NO]
ma11hew28
  • 121,420
  • 116
  • 450
  • 651
23
votes
2 answers

NSFetchedResultsController doesn't show updates from a different context

I have an NSFetchedResultsController and a few operations updates managed objects on separate threads via NSOperationQueue. The FRC (with its predicate) looks like this: - (NSFetchedResultsController*)fetchedResultsController { …
22
votes
2 answers

Which is the best of GCD, NSThread or NSOperationQueue?

What's the best way of multithreading in iOS as we have three options GCD, NSThread, and NSOperationQueue? I am confused in which one is the best? If none, then which should be used in what scenario and how they differ and also, if someone has some…
20
votes
3 answers

Learning NSBlockOperation

I'm a big fan of blocks, but have not used them for concurrency. After some googling, I pieced together this idea to hide everything I learned in one place. The goal is to execute a block in the background, and when it's finished, execute another…
danh
  • 62,181
  • 10
  • 95
  • 136
1
2 3
69 70