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
3 answers

Do NSOperations and their completionBlocks run concurrently?

I've got a bunch of NSOperations added to a NSOperationQueue. The operation queue has the maxConcurrentOperationCount set to 1, so that the NSOperations run one after the other. Now, in the completionBlock of a NSOperation I want to cancel all…
Tom
  • 260
  • 4
  • 13
5
votes
2 answers

Demystify NSOperation: concurrent vs non-concurrent and async pattern

Yes, I know. There are a lot of questions and answers about the NSOperation world but I'm still having some doubts. Il' try to explain my doubts with a two parts question. They are related each other. In the SO post…
Lorenzo B
  • 33,216
  • 24
  • 116
  • 190
5
votes
1 answer

NSOperation: addsubview in the main thread and slowness

I have implemented the following NSOperation, to draw N custom views - (void)main { for (int i=0; i> //(customView is a UIView with some drawing code in drawrect) …
Abramodj
  • 5,709
  • 9
  • 49
  • 75
4
votes
6 answers

Make NSOperation synchronous

I am working on an app that allows an user to create files and folders on the cloud from iPad. When a file is deleted, the app automatically creates a 'Recycle Bin' folder on the cloud and puts that file in it. I have created NSOperationQueue for…
Musti
  • 41
  • 2
  • 3
4
votes
1 answer

performSelector:withObject:afterDelay: within NSOperation

I'm executing some code within some NSOperation objects managed by an NSOperationQueue. The code also contains a delayed method call using performSelector:withObject:afterDelay:. The problem is, that the corresponding selector which should be called…
fabb
  • 11,660
  • 13
  • 67
  • 111
4
votes
5 answers

Debugging an intermittently stuck NSOperationQueue

I have an iOS app with a really nasty bug: an operation in my NSOperationQueue will for some reason hang and not finish executing so other additional operations are being queued up but still not executing. This in turn leads to the app not begin…
Jiho Kang
  • 2,482
  • 1
  • 28
  • 38
4
votes
3 answers

How to stop NSImage lockfocus from Leaking Memory in an NSOperation?

I have a problem with NSImages leaking memory when I draw to them with lock/unlockfocus. The leak goes away when I comment out the LEAKS HERE code below. So I know that is where the leak is happening. for(int i= 0; i < nNumberImages; ++i) { …
Mark
  • 408
  • 3
  • 12
4
votes
1 answer

Executing RestKit as an NSOperartion

I am currently migrating a project that used ASIHTTPRequest and SBJson to RestKit. The previous implementation was using an NSOperation to make the HTTP Request, parse the JSON object and make the necessary calls to the Core Data API. I have…
lucasweb
  • 1,736
  • 5
  • 28
  • 42
4
votes
3 answers

How to cancel specific Operation from OperationQueue in swift

There are 3 Operations in my OperationQueue and i'm not able to cancel specific operation from them. I referred this example but i can't understand it NSOperationQueue cancel specific operations This is my code class myOperation1 : Operation { …
NøBi Mac
  • 505
  • 5
  • 15
4
votes
2 answers

Async NSURLConnection, Concurrent NSOperation, when to use NSRunLoop?

I'm trying to run NSURLConnection async in a secondary thread (target is iOS4), for this I have created a concurrent NSOperation, I think I'm almost there, but am not clear on the following: 1) in iOS4 NSOperationQueue addOperation starts the…
cin
  • 131
  • 1
  • 6
4
votes
3 answers

NSBlockOperation and NSAutoreleasePool

Normally when you create an NSOperation subclass you are responsible for creating and releasing an NSAutoreleasePool in the -main method. When you use an NSBlockOperation, do you need to create an autorelease pool in the block?
Adam Ernst
  • 52,440
  • 18
  • 59
  • 71
4
votes
4 answers

How Important is it to use `performSelectorOnMainThread:withObject:waitUntilDone:` From an NSOperation?

My iPad app syncs with an XML feed, running the sync in an NSOperation subclass executed from an NSOperationQueue. As it parses the feed, it calls back to the main thread via performSelectorOnMainThread:withObject:waitUntilDone: to update various…
theory
  • 9,178
  • 10
  • 59
  • 129
4
votes
1 answer

Cancel NSOperation in for loop?

I am trying to implement search on a background thread using NSOperation on iOS. I didn't want to subclass NSOperation so this is what I'm doing: [searchQueue cancelAllOperations]; NSInvocationOperation *op = [[NSInvocationOperation alloc]…
fabian789
  • 8,348
  • 4
  • 45
  • 91
4
votes
1 answer

NSFetchedResultsController and NSOperation

In a UITableViewController, I use an NSFetchedResultsController for my data. Everything works fine, except for when I start importing some objects in a separate thread: I use an NSOperationQueue in which I insert objects into my…
4
votes
1 answer

Can you use cross-queue dependencies for NSOperation objects?

Is it possible/legal to have cross-queue dependency operations? Consider the following... let operationA = NSBlockOperation(block: someBlock) let operationB = NSBlockOperation(block: someOtherBlock) let operationC = NSBlockOperation(block:…
Mark A. Donohoe
  • 28,442
  • 25
  • 137
  • 286