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
16
votes
2 answers

When does the NSOperationQueue remove an operation from the queue?

I need to know that When does a NSOperationQueue remove an operation from the queue? I have NSOperationQueue which has list of NSOperation. At which point the NSOperationQueue removes an operation from queue? After starting an operation? OR After…
jailani
  • 2,260
  • 2
  • 21
  • 45
15
votes
6 answers

Wait for all Operations in queue to finish before performing task

I have an Operation subclass and Operation queue with maxConcurrentOperationCount = 1. This performs my operations in a sequential order that i add them which is good but now i need to wait until all operations have finished before running another…
WanderingScouse
  • 281
  • 1
  • 3
  • 16
15
votes
5 answers

Waiting for multiple blocks to finish

I have those methods to retrieve some object information from the internet: - (void)downloadAppInfo:(void(^)())success failure:(void(^)(NSError *error))failure; - (void)getAvailableHosts:(void(^)())success …
14
votes
3 answers

Asynchronous NSURLConnection with NSOperation

I want to do NSURLConnection in background mode,because it response is having much data.Forums are telling to use Apple's finite length coding to use in didEnterBackground. but I want to avoid it.instead of it I use following code through…
nameless
  • 809
  • 3
  • 9
  • 27
14
votes
2 answers

Constantly growing memory allocation while fetching images over HTTP in iOS

I am implementing an iOS App that needs to fetch a huge amount of images over HTTP. I've tried several approaches but independently what I do, Instuments shows constantly increasing memory allocations and the App crashes sooner or later when I run…
sink12
  • 141
  • 1
  • 4
14
votes
4 answers

Managing a bunch of NSOperation with dependencies

I'm working on an application that create contents and send it to an existing backend. Content is a title, a picture and location. Nothing fancy. The backend is a bit complicated so here is what I have to do : Let the user take a picture, enter a…
Romain Pouclet
  • 864
  • 2
  • 8
  • 17
13
votes
3 answers

Core Data Multithreading Import (Duplicate Objects)

I have an NSOperationQueue that imports objects into Core Data that I get from a web api. Each operation has a private child managedObjectContext of my app's main managedObjectContext. Each operation takes the object to be imported and checks…
12
votes
4 answers

iOS - How to know when NSOperationQueue finish processing a few operations?

I need in my application to download directories and their content. So I decided to implement a NSOperationQueue and I subclassed NSOperation to implement NSURLRequest etc... The problem is I add all the operations at once and I can't figure out…
Dabrut
  • 862
  • 1
  • 10
  • 25
12
votes
3 answers

Referencing an NSOperation object in its own completion block with ARC

I'm having difficulty converting some NSOperation code to ARC. My operation object uses a completion block, which in turn contains a GCD block that updates the UI on the main thread. Because I reference my operation object from inside its own…
12
votes
6 answers

How to get hold of the currently executing NSOperation?

Is there an equivalent to [NSOperationQueue currentQueue] or [NSThread currentThread] for NSOperation? I have a fairly complex domain model where the heavy processing happens quite deep down in the call stack. In order to timely cancel an operation…
Jon Tirsen
  • 4,750
  • 4
  • 29
  • 27
12
votes
2 answers

NSOperation, start vs main

According to Apple document on NSOperation, we have to override main method for non-concurrent operations and start method for concurrent operations. But why?
Anshu
  • 511
  • 1
  • 5
  • 15
12
votes
2 answers

NSOperation blocks UI painting?

I'm after some advice on the use of NSOperation and drawing: I have a main thread create my NSOperation subclass, which then adds it to an NSOperationQueue. My NSOperation does some heavy processing, it is intended to loop in its main() method for…
Yup
  • 121
  • 1
  • 3
12
votes
1 answer

Continue operation when app did enter background on iOS

in my app i have some NSOperation that update some core data element from a online database, sometime the update require some minute, and when the screen of iPhone lock, the app enter in the background mode, and this update is stopped, so i have to…
Piero
  • 9,173
  • 18
  • 90
  • 160
12
votes
3 answers

AFNetworking: enqueueBatchOfHTTPRequestOperations issue with completion block

I use this AFNetworking method to start multiple requests at once: - (void)enqueueBatchOfHTTPRequestOperations:(NSArray *)operations progressBlock:(void (^)(NSUInteger numberOfCompletedOperations, NSUInteger…
Felix
  • 35,354
  • 13
  • 96
  • 143
12
votes
1 answer

Can I pass delegate as a parameter objective-c

I am working with an NSOperationQueue and I want to add new NSOperations to the NSOperationQueue. It is a queue that lives in a singleton instance of a class I have. It would make things a lot easier if I could move everything into the static…
Slee
  • 27,498
  • 52
  • 145
  • 243
1 2
3
65 66