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

blocks threaded freeze when the UIView moves

All is title :) I have this method : [[NetworkManager sharedInstance] getContentFromUrl:url withId:@"json" onResultBlock:^(NSData *data, NSString *identifier) { NSLog(@"done") } onFailureBlock:^(NSError *error, NSString *identifier)…
0
votes
1 answer

Sibling NSManagedObjectContexts when using NSOperations

I'm running into some trouble working with CoreData in a multithreaded app using NSOperations. I am using nested ManagedObjectContexts through MagicalRecord (2.0.3) as follows: Root Context (saves to disk) | Main Thread Context (for populating the…
0
votes
1 answer

NSXMLParser along with NSOperation is not working properly

To send request to server to download data I am using NSOperation.After receiving data I am using NSXMLParser to parse response but it is not calling parser delegate methods such -(void)parser:(NSXMLParser *)parser didStartElement:(NSString…
Nuzhat Zari
  • 3,398
  • 2
  • 24
  • 36
0
votes
1 answer

Store a NSOperation with Core Data

I need to add persistency to an NSOperationQueue, so the user can close my application without lose any data. I'm a big fan of core data, so I'm looking for a way to store my NSOperation subclass on core data. Any advice?
IgnazioC
  • 4,554
  • 4
  • 33
  • 46
0
votes
1 answer

Objective c - Canceling operations in NSOperationQueue

I'm using AFNetworking AFHTTPClient just for the example, but this question is about NSOperationQueue in general. The AFHTTPClient manage an NSOperationQueue for requests made by the client. It also has a cancelAllOperations method that iterate…
Eyal
  • 10,777
  • 18
  • 78
  • 130
0
votes
2 answers

Why should I create the context in main for a serial queue and in start for a concurrent queue?

There is topic about Thread Confinement pattern in Core Data programming Guide and it says that You must create the managed context on the thread on which is will be used. If you use NSOperation, note that its init method is invoked on the same…
folex
  • 5,122
  • 1
  • 28
  • 48
0
votes
0 answers

Stacktrace involving a NSOperation release

I receive crash reports which are quite obscure. What is the strategy with stack traces such as the following. Thread 7 crashed 0 libobjc.A.dylib objc_msgSend + 9 1 Foundation -[NSOperation release] + 148 2 Foundation __release_object_op + 22 3…
Kamchatka
  • 3,597
  • 4
  • 38
  • 69
0
votes
1 answer

Using NSOperationQueue as a view controller instance variable

If I have a view controller that has an NSOperationQueue as an instance variable, then what happens to any operations that are executing in the queue if the view controller gets unloaded?
John Topley
  • 113,588
  • 46
  • 195
  • 237
0
votes
1 answer

connection:didReceiveResponse: from NSURLConnectionDelegate never fired

I'm trying to get UIProgressView, NSURLConnection, NSOperation and NSOperationQueue working together. Here is the code: http://pastie.org/4080576 Problem: connection:DidReceiveData: never called: execution going immediately to -start(), through…
0
votes
1 answer

Cocoa app behaves diffirently with breakpoint on & off

Important update: I found out that most part of my question was based on a false premise (see my answer below). Notifications actually got to the receiver, they just got there too fast. (Although, it still doesn't explain why the behavior with…
Max Yankov
  • 12,551
  • 12
  • 67
  • 135
0
votes
1 answer

Resend ASIHTTPRequest when connection returns

I am using ASIHTTPRequest to interact with my website. I am basically adding ASIHttpRequests to a queue. It all works fine if there is an internet connection. However, I guess the operation gets deleted if the request fails (ie, no internet…
0
votes
1 answer

Calling performSelectorOnMainThread with NSOperation

I have an issue where I have a NSOperation running in a background thread, and in the execution loop of that execution i call performSelectorOnMainThread to execute a NSURLRequest, But the main thread never gets the call to execute that…
stephen
  • 1,617
  • 3
  • 20
  • 27
0
votes
1 answer

NSURLConnection sendSynchronousRequest not blocking

I'm calling NSURLConnection -sendSynchronousRequest in NSOperation, but the method returns immediately. I would expect it to block the operation until all data is received. Is this a misunderstanding on my part?
Morrowless
  • 6,856
  • 11
  • 51
  • 81
0
votes
2 answers

iOS : Best way to organise multithreading

Guys I need some help to architect my multithreading in iOS. I'm using ARC in my code. So basically I need following, In my main thread nstimer fire some method which should be executed in a separate thread, that thread does some calculation and…
deimus
  • 9,565
  • 12
  • 63
  • 107
0
votes
2 answers

dealloc in NSOperation

i have a NSOperationQueue with NSOperation, in my NSOperation .h i have this property: @interface MyOperationClass : NSOperation @property (strong, nonatomic) NSFetchedResultsController *fetchedResultsController; @property (strong, nonatomic)…
Piero
  • 9,173
  • 18
  • 90
  • 160