nsoperation

performSelector in NSOperation subclass

[亡魂溺海] 提交于 2019-12-24 00:52:35
问题 I couldn't find an answer anywhere else on the net so any help would be appreciated. I am tying to create a system whereby I can retrieve the results of an NSOperation task, which I understand cannot be done by concrete subclasses such as NSInvocation. I have an NSOperation subclass ( TheEngine ) which is abstract by convention and must be extended to implement the function -main , to include the body of code to execute. TheEngine contains the following initialisation function whose job is

Swift: Retain cycle with NSOperation

假如想象 提交于 2019-12-23 12:43:10
问题 In my app I use an image loader class to load images from the web for a collection view. The class keeps track of the download operations and cancels them when the cells for the images are no longer visible in the collection view. This implementation is based on the raywenderlich tutorial for NSOperation: http://www.raywenderlich.com/76341/use-nsoperation-nsoperationqueue-swift. I use NSOperation for downloading an image from the web. I noticed with Instruments that none of the NSoperations

NSURLConnection, NSOperation and NSRunLoop confusion over threading

痞子三分冷 提交于 2019-12-23 06:55:35
问题 I got confused while working with NSURLConnection and NSRunLoop. I’m trying to download a large file using NSURLConnection but it’s NOT working (Not even calling a single delegate method) as expected. NSURL *url = [NSURL URLWithString:@"http://127.0.0.1:8080/"]; NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] initWithURL:url] autorelease]; [request setHTTPBody:[@"Request Body Data" dataUsingEncoding:NSUTF8StringEncoding]]; [request setHTTPMethod:@"POST"]; Running on main Thread.

Why is my NSOperationQueue not behaving correctly in iOS 4.0?

独自空忆成欢 提交于 2019-12-23 04:51:17
问题 I have used NSOperationQueue in my iPhone app before in iPhone OS 3.0, but now in iOS 4.0 the code is not working properly. It runs properly only once and on all subsequent calls, it doesnt work. Have there been changes in NSOperationQueue in iOS 4.0? The relevant code is as follows: - (void) starteffectFunction { NSOperationQueue *queue = [NSOperationQueue new]; NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(starteffectProcessing)

AFURLConnectionOperation 'start' method gets called before it is ready and never gets called again afterwards

一笑奈何 提交于 2019-12-23 03:44:09
问题 We use AFNetworking (https://github.com/AFNetworking/AFNetworking) in our app and NSOperationStack (https://github.com/nicklockwood/NSOperationStack) to set dependencies so that last operation gets priority over the rest in the queue (stack behavior). I am running into an issue when 'start' method of AFURLConnectionOperation gets called, but operation's 'isReady' method returns NO because of the dependencies. This makes 'start' exit immediately. After the very first attempt to start operation

NSOperationQueue: a sequence of NSOperation's with dependencies VS (maxConcurrentOperationCount == 1)?

蓝咒 提交于 2019-12-23 02:46:26
问题 For example I have 3 objects: NSOperation *op1 = ...; NSOperation *op2 = ...; NSOperation *op3 = ...; [op3 addDependency:op2]; [op2 addDependency:op1]; NSOperationQueue *queue = ...; queue.maxConcurrentOperationCount = 1; [queue addOperations:@[op1, op2, op3] waitUntilFinished:NO]; I could simply add all the operations in correct order. But for example if op2 is cancelled then I should also cancel op3 and I can't fully clear a queue in this case. My questions: 1)Is it safe to combine such

NSOperation KVO isFinished

亡梦爱人 提交于 2019-12-22 09:13:19
问题 Im trying to subclass a NSOperation, and read some sample from, they say: when the task finished, using KVO of NSOperation, to finish the operation, code here: [self willChangeValueForKey:@"isFinished"]; [self willChangeValueForKey:@"isExecuting"] finished = YES; executing = NO; [self didChangeValueForKey:@"isFinished"]; [self didChangeValueForKey:@"isExecuting"]; then isFinished get called - (BOOL) isFinished{ return(finished); } anyone could explain this to me? why isFinished gets called,

How use sqlite + fdbm library with threading on the iPhone

吃可爱长大的小学妹 提交于 2019-12-21 20:28:11
问题 Related to this SO question, I want to put the data loading in the background. However, I get 'library routine called out of sequence' errors. In this SO thread say that the way is using NSOperation, but looking on the samples on the web I not know how that could solve the issue. I share a single sqlite connection with the singleton pattern: @interface Db : NSObject { NSString *path; FMDatabase* theDb; BOOL isOpen; } @property (retain, nonatomic) FMDatabase *theDb; @property (retain,

Why my completionBlock never gets called in an NSOperation?

瘦欲@ 提交于 2019-12-21 03:47:22
问题 I've sublcassed an NSOperation and set my completionBlock but it seems to never enter even when the operation finishes. Here's my code: A catalog controller class sets up the NSOperation: - (void)setupOperation { ... ImportWordOperation *importWordOperation = [[ImportWordOperation alloc] initWithCatalog:words]; [importWordOperation setMainObjectContext:[app managedObjectContext]]; [importWordOperation setCompletionBlock:^{ [(ViewController *)[[app window] rootViewController] fetchResults]; }]

What is the difference between NSInvocationOperation and NSBlockOperation

给你一囗甜甜゛ 提交于 2019-12-20 10:32:37
问题 There are three operation classes in Foundation Framework( NSOperation , NSInvocationOperation and NSBlockOperation ). I already read the concurrency programming guide but I did't understand exactly what is the difference between these three classes. Please help me. 回答1: NSBlockOperation exectues a block. NSInvocationOperation executes a NSInvocation (or a method defined by target, selector, object). NSOperation must be subclassed, it offers the most flexibility but requires the most code.