Questions tagged [nsoperation]

The NSOperation class is an abstract class you use to encapsulate the code and data associated with a single task

The NSOperation class is an abstract class you use to encapsulate the code and data associated with a single task. Because it is abstract, you do not use this class directly but instead subclass or use one of the system-defined subclasses (NSInvocationOperation or NSBlockOperation) to perform the actual task. Despite being abstract, the base implementation of NSOperation does include significant logic to coordinate the safe execution of your task. The presence of this built-in logic allows you to focus on the actual implementation of your task, rather than on the glue code needed to ensure it works correctly with other system objects.

An operation object is a single-shot object—that is, it executes its task once and cannot be used to execute it again. You typically execute operations by adding them to an operation queue (an instance of the NSOperationQueue class). An operation queue executes its operations either directly, by running them on secondary threads, or indirectly using the libdispatch library (also known as Grand Central Dispatch). For more information about how queues execute operations, see NSOperationQueue Class Reference.

If you do not want to use an operation queue, you can execute an operation yourself by calling its start method directly from your code. Executing operations manually does put more of a burden on your code, because starting an operation that is not in the ready state triggers an exception. The isReady method reports on the operation’s readiness.

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/NSOperation_class/Reference/Reference.html

983 questions
5
votes
1 answer

Exactly when NSOperation is removed from NSOperationQueue on cancelling request?

I was going through some documents explaining how to manage NSOperation inside NSOperationQueue. My focus is to always do not execute the operation at all if the user pressed a cancel button in a progress panel or quit the application. And thus,…
5
votes
1 answer

NSOperationQueue : cancel an operation after a timeout given

Basically, I would like to perform a cancel if the operation I'm adding to the queue does not respond after a certain timeout : NSOperationQueue * queue = ... [self.queue addOperationWithBlock:^{ // my block... } timeoutInSeconds:5.0…
Nicolas Henin
  • 3,244
  • 2
  • 21
  • 42
5
votes
1 answer

NSAssert usage in threads

I'm trying to use NSAssert throughout my iPhone app so that if an unexpected condition occurs, the application fails-fast and crashes with a meaningful message in the crash log. This works fine if the failing NSAssert is on the main thread, as it…
Trashpanda
  • 14,758
  • 3
  • 29
  • 18
5
votes
4 answers

Use of delegates in NSOperation

I am trying to make use of CLLocationManager in an NSOperation. As part of this I require the ability to startUpdatingLocation then wait until a CLLocation is received before completing the operation. At present I have done the following, however…
user843337
5
votes
2 answers

Pass data from NSOperation to next NSOperation

Is it possible to pass data from an NSOperation up the dependency chain to be used by the next NSOperation? Thanks Chris
Chris
  • 2,739
  • 4
  • 29
  • 57
5
votes
2 answers

Magical Record background save seems to be blocking UI

I have a NSOperation that I put in a queue. The NSOperation does some long running photo processing then I save the information/meta data in core data for that photo. In the main method of my custom NSOperation class is where I execute the below…
inks2002
  • 377
  • 4
  • 13
5
votes
2 answers

How to block an NSOperation until an NSOperationQueue finishes?

I have a data loading operation that needs to be run off the main thread to avoid potential blocking issues. To do this, I use an NSOperationQueue and NSOperations. One issue that has come up, however, is that one of the operations exists to spawn…
RonLugge
  • 5,086
  • 5
  • 33
  • 61
5
votes
3 answers

Problems Queuing Concurrent & Non-Concurrent NSOperations

I have an NSOperationQueue which contains 2 NSOperations and is set to perform them one after another by setting setMaxConcurrentOperationCount to 1. One of the operations is a standard non-concurrent operation (just a main method) which…
Michael Waterfall
  • 20,497
  • 27
  • 111
  • 168
5
votes
2 answers

NSOperationQueue waitUntilAllOperationsAreFinished not working while in background

The app I'm working on periodically refreshes it's local data cache from an application server (10+ requests, each of them take a fair amount of time). I'm currently running these requests asynchronously as to not block the UI thread. Since these…
chinabuffet
  • 5,278
  • 9
  • 40
  • 64
5
votes
1 answer

ViewController type name not recognized in one class, but it is in another?

I am getting a build semantic error in XCode when I attempt to build my project. I have 3 NSOperation classes setup to download information from the internet, process it, and send it to the parent view controller, an instance of ViewController. Here…
Liftoff
  • 24,717
  • 13
  • 66
  • 119
5
votes
2 answers

Keep running NSOperationQueue when app goes to background

I'm downloading files using NSOperation (s) and adding them NSOperationQueue. NSOperationQueue is getting suspended when app goes in the background. Is there any work around if queue will not suspend in the background and start the next operation?
5
votes
2 answers

NSInvocationOperation callback too soon

I know similar questions have been asked a few times, but I'm struggling to get my head around how this particular problem can be solved. So far, everything I've done has been carried out on the main tread. I now find that I need to perform an…
beev
  • 1,197
  • 2
  • 16
  • 33
5
votes
2 answers

Which one is easier to use? GCD or NSOperation?

I am currently using GCD. However, I've heard that NSOperation is actually a higher level program. It's far more complex though. In GCD, do something at background is simply use this helper function I created: +(void)doForeGround:(void…
5
votes
2 answers

NSOperation VS GCD for Core-Data

What is more suitable for a situation where data needs to be stored in Core-Data on one thread and read from Core-Data on another? I was thinking of GCD but how does it work with the creation of the NSManagedObjectContext for each thread? How does…
some_id
  • 29,466
  • 62
  • 182
  • 304
5
votes
1 answer

Is it safe to set NetworkActivityIndicatorVisible value in secondary thread?

I wonder if AppDelegate is thread safe? I currently have an operation running networking tasks on the secondary thread, when the task begins, I would like to set NetworkActivityIndicatorVisible to YES, and when the task is done, set it to NO. Do I…
Jason
  • 814
  • 1
  • 6
  • 15