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

Drawing in a background thread on iOS

I have a view with some very complex drawing logic (it's a map view that draws from GIS data). Doing this drawing on the main thread locks up the UI and makes the app unresponsive. I want to move away the drawing to a background thread with for…
Jon Tirsen
  • 4,750
  • 4
  • 29
  • 27
6
votes
4 answers

Managing CPU intensive threads on iOS

I’m an experienced C/C++ programmer coming up to speed on Objective C on the iPhone. I have done a lot of searching, but haven’t found a satisfactory answer on what must be a common question; I apologize if this is answered elsewhere, pointers…
user938797
  • 167
  • 3
  • 15
6
votes
3 answers

What is ASIHTTPRequest?

What is ASIHTTPRequest? how do we use it in an iphone application? what are the files we need to include? Does Apple provide files for this?
iOS
  • 423
  • 1
  • 6
  • 15
6
votes
8 answers

Understanding sequence of operations with dependency in Swift

Referring https://developer.apple.com/reference/foundation/operation, I am having Playground setup as - class myOperation1 : Operation { override func main() { print("op1 working....") } } class myOperation2 : Operation { …
BaSha
  • 2,356
  • 3
  • 21
  • 38
6
votes
3 answers

How to resume time out operations NSOperationQueue in iOS?

I have already implemented NSOperationQueue successfully in application. I have one operation queue which might have 1000 of NSOperations like below. @interface Operations : NSOperation @end @implementation Operations - (void)main { NSURL…
Jayeshkumar Sojitra
  • 2,501
  • 4
  • 31
  • 44
6
votes
2 answers

CloudKit: CKFetchRecordChangesOperation, CKServerChangeToken and Delta Download

My question is related to the "Delta Download" thing as it was named in WWDC 2014 Advanced CloudKit. I'm trying to make syncronization for my Core Data app, which is iPhone only for now (think: there is only one device active). So, basically the app…
Dima Deplov
  • 3,688
  • 7
  • 45
  • 77
6
votes
1 answer

Why does NSOperationQueue on iPhone OS 3.1 hold on to long-cancelled (and released) operations?

I have an app that uses NSOperations to manage service calls to a web API (the calls are based on CURLOperation in Jon Wight's touchcode). There is a certain call that downloads map locations when the center of a map view changes significantly;…
qwzybug
  • 553
  • 4
  • 14
6
votes
5 answers

Why my NSOperation is not cancelling?

I have this code to add a NSOperation instance to a queue let operation = NSBlockOperation() operation.addExecutionBlock({ self.asyncMethod() { (result, error) in if operation.cancelled { return } // etc …
StackOverflower
  • 5,463
  • 13
  • 58
  • 89
6
votes
4 answers

Can I cancel a Block added to an NSOperationQueue with addOperationWithBlock:?

I've read many many articles which say "BLOCKS ARE THE FUTURE!!!". I'm wondering if it relates to running operations in the background. For example, I have a table view which has images that will come from the web. Right now I can get them using…
6
votes
2 answers

Return data from NSOperation?

I'm creating a lot of NSOperations (subclasses) that sort through a bunch of data. When they're done, I'd like them "return" that data and put it into a mutable array or something. Order doesn't matter. Is something like this is possible?
user2529626
6
votes
3 answers

What does isConcurrent mean for NSOperation running from NSOperationQueue?

Because NSOperationQueue always run tasks on a new thread, I'm confused about the role of isConcurrent when NSOperation runs from NSOperationQueue. If i have two subclasses of NSOperation, both running an async processes, both are launched from…
amit
  • 2,171
  • 4
  • 31
  • 50
6
votes
3 answers

Asynchronous url requests inside dispatch_async

I am trying to implement asynchronous url requests in a particular function, I want all these requests to complete and then do a particular action but the action precedes the requests i.e, it is getting called before the requests…
Satheesh
  • 10,998
  • 6
  • 50
  • 93
6
votes
3 answers

How lightweight is NSOperationQueue on Snow Leopard?

I'm working with some code that does a bunch of asynchronous operating with various callbacks; Snow Leopard has made this incredibly easy with blocks and GCD. I'm calling NSTask from an NSBlockOperation like so: [self.queue addOperationWithBlock:^{ …
Jim Puls
  • 79,175
  • 10
  • 73
  • 78
6
votes
4 answers

Best way to deal with a change in internet connection with HTTP networking

Normally, in my iOS Applications that use quite a lot of HTTP requests to communicate with the server, I add an NSBlockOperation to the app's global NSOperationQueue, and then suspend and enable the queue when the application detects a change in…
max_
  • 24,076
  • 39
  • 122
  • 211
5
votes
4 answers

Copying pending changes between NSManagedObjectContexts with shared persistent store?

I have two instances of NSManagedObjectContext: one is used in main thread and the other is used in a background thread (via an NSOperation.) For thread safety, these two contexts only share an NSPersistentStoreCoordinator. The problem I'm having is…