nsoperation

Blocks within NSOperation

一个人想着一个人 提交于 2019-12-11 01:42:19
问题 I'm using AFNetworking to perform URL request and defining success/error blocks within NSOperation - so that's basically running asynchronous process within NSOperation. I understand the caveat behind this approach, being NSOperation would terminate prematurely before delegate methods are called and therefore have implemented one of the suggested solutions by running start() on the main thread (relevant post Asynchronous methods in NSOperation). So far that's all good, I can see that the

How to check if NSOperationQueue is finished and if any operation failed?

北慕城南 提交于 2019-12-10 23:42:13
问题 I'm trying to parse some XML files in the background so that the UI doesn't freeze. I have to check two things: NSOperationQueue is finished? NSOperation - parsing did fail? I have a class that subclasses NSOperation and a delegate is called if the parsing failed. Operations in the queue are limited to one simultaneously. My problem is that I can't rely on the fact that the failed message is executed before I get the queue did finish message. Sometimes I don't get a failed message before I

CKFetchRecordsOperation + CKQueryOperations … what am I missing?

女生的网名这么多〃 提交于 2019-12-10 22:39:49
问题 Managed to cobble together a CKFetchRecordsOperation after much searching for sample code; and here it is... but I must have missed something. Don't get me wrong it works a treat... but... To execute a CKFetchRecordsOperation you need an NSArray of CKRecordIDs; to get a NSArray of CKRecordIDs, you need to execute CKQuery thru which you can build your NSArray of CKRecordIDs. But wait a minute, the process of extracting the CKRecordIDs uses a CKQuery, thru which I could simply download the

How to assure that operations in an OperationQueue are finished one after another

本秂侑毒 提交于 2019-12-10 16:29:37
问题 When performing operations that are dependent on each other OperationQueue could be used to assure they are executed in the correct order. However, would it also be possible to assure that operations are finished one after another? Let's assume a method that is performed asynchronous and takes some time to finish: public func performOperation(_ number: Int, success: @escaping (Int) -> Void)->Void { DispatchQueue(label: "operations").async { print("Operation #\(number) starts") usleep(useconds

Chaining `NSOperation` : Pass result from an operation to the next one

我们两清 提交于 2019-12-10 15:32:16
问题 I've been looking for a way to pass results for chained NSOperation . For example, lets assume we have 3 operations chained: Operation1 to download JSON data from server Operation2 to parse & model JSON received Operation3 to download user images So Op3 would be dependent on Op2, which is dependent on Op1. But I'm looking for way to pass results from Op1 -> Op2, then from Op2 -> Op3 as: [operation1 startWithURL:url]; [operation2 parseJSONfromOp1IntoModel:JSONData]; [operation3

Magic of NSOperation internals - how does it observe isFinished key so that completionBlock is always run?

守給你的承諾、 提交于 2019-12-10 10:01:49
问题 Demonstration - (void)test_NSOperationCallsCompletionBlockWhenFinished { __block BOOL flag = NO; NSOperation *operation = [NSOperation new]; operation.completionBlock = ^{ NSLog(@"Hunting NSOperation internals: %@", [NSThread callStackSymbols]); flag = YES; }; [operation start]; while (flag == NO); STAssertTrue(flag, nil); } Gives me the following input: 2013-07-28 19:59:44.690 SACompositeOperationsApp[99551:3103] Hunting NSOperation internals: ( 0 SACompositeOperationsApp 0x000000010005bbd9

Subclassing NSOperation to internet operations with retry

喜你入骨 提交于 2019-12-10 08:03:50
问题 I'm subclassing NSOperation for http post in background thread. Those specific http posts doesn't require any value to return. What I'm trying to do is when I've an error or timeout I want it to send after an increasing delay (fibonacci). So far I've done this: NSInternetOperation.h: #import <Foundation/Foundation.h> @interface NSInternetOperation : NSOperation @property (nonatomic) BOOL executing; @property (nonatomic) BOOL finished; @property (nonatomic) BOOL completed; @property (nonatomic

How do I start an Asynchronous NSURLConnection inside an NSOperation?

痴心易碎 提交于 2019-12-09 00:48:57
问题 I want to do an Asynchrous NSURLConnection inside of an NSOperation on a background thread. it is because I'm doing some very expensive operations on the data as they come back. This is a very similar question to what they asked here: How do I do an Asynchronous NSURLConnection inside an NSOperation? but the difference is that I run the connection in another class. Here is my first attempt: In my MainViewController: @property (nonatomic, strong) NSOperationQueue *requestQueue; #pragma mark -

How do I cancel an NSOperation's dependencies?

ぐ巨炮叔叔 提交于 2019-12-08 15:48:41
问题 I have some NSOperation s in a dependency graph: NSOperation *op1 = ...; NSOperation *op2 = ...; [op2 addDependency:op1]; Here's how I'm running them: NSOperationQueue *queue = [[NSOperationQueue alloc] init]; [queue addOperation:op1]; [queue addOperation:op2]; Now I need to cancel them. How do I ensure that all the NSOperation s in a dependency graph are cancelled, and that no other NSOperation s are cancelled? what I've tried: Calling cancel on either NSOperation doesn't cancel the other

How to get hold of the currently executing NSOperation?

断了今生、忘了曾经 提交于 2019-12-08 15:36:41
问题 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 I would need to pass the NSOperation as a parameter to every method until I get to the point where I want to interrupt a longer running loop. Using threads I could use [[NSThread currentThread] isCancelled] so it would seem convenient if there is