Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS MKNetworkOperation - how to retry the last operation?
    text
    copied!<p>I am trying to implement a refresh-function. I have multiple types of operations populating my tableview, and I simply want to re-run the last operation.</p> <p>I have this property:</p> <pre><code> @property (nonatomic, strong) GetRouteOperation* refreshOperation; </code></pre> <p>Where the RouteOperation inherits from MKNetworkOperation, and it is a superclass of different types of RouteOperations, for example "Get routes in radius", "Get routes by cities", etc.</p> <p>Im initializing the operation like this:</p> <pre><code>GetRoutesWithinDistanceOperation *operation = [[GetRoutesWithinDistanceOperation alloc] initOperation]; [self refreshRoutesWithOperation:operation]; </code></pre> <p>Im running the operation like this:</p> <pre><code>- (void)refreshRoutesWithOperation:(GetRouteOperation *)operation { self.refreshOperation = [operation copyForRetry]; [operation getRoutesCompletionHandler:^(NSArray *routes) { self.routes = routes; [self.tableView reloadData]; } errorHandler:^(NSError *error) { } notModifiedHandler:^{ }]; } </code></pre> <p>and it works the first time I fetch my data.</p> <p>When I try to refresh the table like this:</p> <pre><code> [self refreshRoutesWithOperation:self.refreshOperation]; </code></pre> <p>I get an exception in this method for the MKNetworkOperation-class:</p> <pre><code>-(void) addCompletionHandler:(MKNKResponseBlock)response errorHandler:(MKNKResponseErrorBlock)error { if(response) [self.responseBlocks addObject:[response copy]]; if(error) [self.errorBlocksType2 addObject:[error copy]]; } </code></pre> <p>this is the exception:</p> <pre><code>2013-08-30 14:00:32.211 AppName[3500:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI addObject:]: unrecognized selector sent to instance 0x9960540' </code></pre> <p>Why?! Why can't I simply run the copied operation like the first time.</p> <p>EDIT:</p> <p>It seems as if the actual copyForRetry doesn't work for me. Or I am using it in a wrong way.</p> <p>Even if I try to use the copied object directly after copying it, It crashes. This does not work; I get the same exception:</p> <pre><code>self.refreshOperation = [operation copyForRetry]; [self.refreshOperation getRoutesCompletionHandler:^(NSArray *routes) { ... } </code></pre> <p>Anyone got a good solution for this? How to store the last operation for refreshing purposes?</p> <p>Edit2: I try to use the NSObject method copy aswell, but still get the same problem. I guess there's something I'm missing with the copy-methods.</p> <p>However I do not need to use this approach for a solution, I just need a smooth solution. Any ideas?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload