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
4
votes
1 answer

How to cancel a cloudKit operation due to timeout in Swift?

I am looking for help about how to cancel a cloudKit operation due to a given timeout setting? My case is I use CKModifyRecordsOperation upload some changes to iCloud, if failed, I will save those failed records to local storage. But something, the…
tiantong
  • 104
  • 6
4
votes
1 answer

Is using NSOperationQueue with NSURLSession to introduce dependency among the calls a bad approach?

I have strange situation here. Assume you have task1 (NSURLSessionUploadTask) and it is uploading some huge data and user initiates task2 (NSURLSessionDataTask) which should not execute if task1 fails. On the other hand he might start another task3…
Sandeep Bhandari
  • 19,999
  • 5
  • 45
  • 78
4
votes
3 answers

Cancelled NSOperation EXC_BAD_ACCESS crash when setting isFinished

I have an NSOperation subclass that runs async operations from a UITableView. I override the correct start and finish methods like this: - (void)start { [self willChangeValueForKey:@"isExecuting"]; self.isExecuting = YES; [self…
Darren
  • 10,182
  • 20
  • 95
  • 162
4
votes
1 answer

Swift: Retain cycle with NSOperation

In my app I use an image loader class to load images from the web for a collection view. The class keeps track of the download operations and cancels them when the cells for the images are no longer visible in the collection view. This…
Leontien
  • 612
  • 5
  • 22
4
votes
3 answers

NSOperation dependency and completionBlock

We're having a simple problem regarding NSOperationQueue, here's a simple operation logic: self.queue = [[NSOperationQueue alloc] init]; NSOperation *operationA = [NSBlockOperation blockOperationWithBlock:^{ NSLog(@"- Running operation A"); …
4
votes
2 answers

Chaining `NSOperation` : Pass result from an operation to the next one

I've been looking for a way to pass results for chained NSOperation. For example, lets assume we have 3 operations chained: Operation1 to download JSON data from server Operation2 to parse & model JSON received Operation3 to download user…
Haitham
  • 83
  • 4
4
votes
2 answers

Extra retain needed on NSOperation

I'm developing an iPad app. It uses an NSOperation to download something in the background, processed by an NSOperationQueue. I'm finding that, unless I add a retain to the NSOperation, I hit a crash after the operation's action is performed. …
Shaheen
  • 51
  • 1
4
votes
1 answer

NSOperation & NSOperationQueue Cancellation

I'm encountering some weird issues with some custom NSOperation instances queued in an NSOperationQueue instance: When I call either [myOperation cancel] or [myOperationQueue cancelAllOperations] the isCancelled getter for the cancel boolean remains…
Razvan
  • 4,122
  • 2
  • 26
  • 44
4
votes
1 answer

NSOperationQueue addOperations waitUntilFinished

Hi I am building an app using Swift. I need to process notifications in a specific order. Therefore I am trying to use addOperations waitUntilFinished. Here is what I did: let oldify = NSOperation() oldify.completionBlock =…
Quentin Malgaud
  • 405
  • 6
  • 21
4
votes
1 answer

Difference between performSelectorInBackground and NSOperation Subclass

I have created one testing app for running deep counter loop. I run the loop function in background thread using performSelectorInBackground and also NSOperation subclass separately. I am also using performSelectorOnMainThread to notify main thread…
AmitSri
  • 1,209
  • 1
  • 20
  • 48
4
votes
1 answer

iPhone: NSOperationQueue running operations serially

I have a singleton NSOperationQueue that handles all of my network requests. I'm noticing, however, that when I have one particularly long operation running (this particular operation takes at least 25 seconds), my other operations don't run until…
Greg Maletic
  • 6,225
  • 8
  • 54
  • 73
4
votes
1 answer

How do I override a getter for a KVO-compliant property?

I want to create a subclass of NSOperation that needs to customize -isReady, the getter for a KVO-compliant property. My override would do a Boolean-AND of my custom test and super's version of the method. But the override still has to keep…
CTMacUser
  • 1,996
  • 1
  • 16
  • 27
4
votes
2 answers

NSOperation. Cancellation vs Complete status

I have an NSOperation with an NSOperationQueue that has a bunch of child operations, some queued up. I had a problem where even after calling cancelAllOperations on the queue my main method was hanging on waitUntilAllOperationsAreFinished. Then when…
Mitchell Currie
  • 2,769
  • 3
  • 20
  • 26
4
votes
2 answers

SocketRocket connection pausing while in background

I am using SocketRocket, but I cannot get it to deliver messages while in the background. When I open the app again, it resumes the connection (without reconnecting) and the messages all come in at once. Here is my connection code: -…
Jason Silberman
  • 2,471
  • 6
  • 29
  • 47
4
votes
2 answers

Subclassing NSOperation to internet operations with retry

I'm subclassing NSOperation for http post in background thread. Those specific http posts doesn't require any value to return. What I'm trying to do is when I've an error or timeout I want it to send after an increasing delay (fibonacci). So far…
Idan Moshe
  • 1,675
  • 4
  • 28
  • 65