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

How to ensure the item of a UIActivityItemProvider is ready when UIActivityViewController presents it?

According to the docs [UIActivityItemProvider item] is run on a secondary thread. This is great for not locking up the UI, but I am finding that it does not always complete by the time the item is shown, for instance in a Mail compose screen. I am…
akaru
  • 6,299
  • 9
  • 63
  • 102
0
votes
1 answer

Waiting for an AFHTTPRequestOperation to complete before continuing

i'm trying to make an iOS App that communicates with an API using AFHTTPClient. The first step is to authentificate the user, to do so, i use this code: -(void)authorize { NSURLRequest *request = [httpClient requestWithMethod:@"POST"…
Abel
  • 315
  • 1
  • 4
  • 18
0
votes
1 answer

Show activityView WHILE waiting operation end in NSOperationQueue and AFNetworking

I have found a way to queue JSON parsing operation to wait complete data parse, and this is the code: - (void)LoadParse { // this method is called by a UIButton NSURLRequest *request = [NSURLRequest requestWithURL:url…
0
votes
1 answer

NSOperation Data Parsing Best Practice

I have a question about best practice in downloading data using NSOperation. Currently I am using NSOperationQueue to make multiple requests for JSON data on a remote server. When the data comes in I break it apart into one large NSDictionary and…
AgnosticDev
  • 1,843
  • 2
  • 20
  • 36
0
votes
1 answer

TableView data does not get updated with NSOperation

So I'm not sure if I set this up correctly. I have a SearchDisplayController and search bar. UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 150, 44)]; self.SearchEntry = searchBar; self.SearchEntry.tintColor =…
Crystal
  • 28,460
  • 62
  • 219
  • 393
0
votes
1 answer

NSOutputStream is always waiting for space available after second NSOperation tries to write to it

I am creating an NSOutputStream and passing it to an NSOperation, which I call from an NSOperationQueue. In the operation, I am polling for hasSpaceAvailable so that I can write out to the socket. This works fine the first time I write out to the…
ayl
  • 384
  • 1
  • 5
  • 14
0
votes
1 answer

NSOperation fails when switching the tab bar

I am using a TabBarController with two tabs. In the second I am calling an NSOperation, adding the operation to an NSOperationQueue. When I select the second tab, I have called this operation on the main thread. But when I switch to the first tab…
Nassif
  • 1,113
  • 2
  • 14
  • 34
0
votes
2 answers

SEGV_ACCERR and crash app sometime on NSOperation when do [self.managedObjectContext save:&error]

I have a problem that I can't understand how to handle because does not happen logically. I have some NSOperations that run concurrently. For example, - (void)main { @autoreleasepool { AppDelegate *appController =…
Piero
  • 9,173
  • 18
  • 90
  • 160
0
votes
2 answers

NSTimer not working when used in different functions

When I use it like that the ns timer worksi.e its calling both foo1 and foo1 -(void)register1 { NSRunLoop * runLoop = [NSRunLoop currentRunLoop]; [runLoop addTimer:[NSTimer scheduledTimerWithTimeInterval:10 target:self…
zzzzz
  • 1,209
  • 2
  • 18
  • 45
0
votes
1 answer

check when two NSOperationQueue have finished to call endBackgroundTask for stopping background task mode

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

NSDictionary passed to NSOperation is null inside the invoked method

I'm using the code below to pass multiple values to NSOperation. I have defined an NSDictionary but I can't access on it (it returns always null) within the method called. Below is my code to invoke the method NSDictionary *params = [[NSDictionary…
0
votes
1 answer

iOS Multi-threaded core-data app not merging changes

I have an iOS app which is accessing a core data sql database from two threads. Thread A (the main UI thread) updates a core data record, and Thread B then attempts to read from the Entity collection that Thread A has just updated. Trouble is,…
Journeyman
  • 10,011
  • 16
  • 81
  • 129
0
votes
1 answer

Correct usage: NSOperation and NSInvocationOperation

I am studing about NSOperation and I have a doubt about the correct way of implementing it for my situation. In my app I want to perfom a lot of operations in background. Since my app can import data from a desktop software, my database can become…
Rafael
  • 1,655
  • 3
  • 17
  • 25
0
votes
1 answer

ASIHTTPRequest in ASINetworkQueue: Cancel request while queue is running

I am using ASIHTTPRequest (I know, I know, it is not being maintained - that doesn't matter; it works and it is what my app is built on) to run a series of HTTP requests through ASINetworkQueue. The problem is that my queue will have many requests…
Jason
  • 14,517
  • 25
  • 92
  • 153
0
votes
1 answer

How do i store nsoperation into nsuserdefaults?

I have an nsoperation class where I want to store that running operation into nsuserdefaults for later reference. How do I do that? Please help.