nsoperationqueue

NSThread vs. NSOperationQueue vs. ??? on the iPhone

半腔热情 提交于 2019-11-26 22:33:32
问题 Currently I'm using NSThread to cache images in another thread. [NSThread detachNewThreadSelector:@selector(cacheImage:) toTarget:self withObject:image]; Alternately: [self performSelectorInBackground:@selector(cacheImage:) withObject:image]; Alternately, I can use an NSOperationQueue NSInvocationOperation *invOperation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(cacheImage:) object:image]; NSOperationQueue *opQueue = [[NSOperationQueue alloc] init]; [opQueue

How do I use NSOperationQueue with NSURLSession?

我是研究僧i 提交于 2019-11-26 22:30:58
问题 I'm trying to build a bulk image downloader, where images can be added to a queue on the fly to be downloaded, and I can find out the progress and when they're done downloading. Through my reading it seems like NSOperationQueue for the queue functionality and NSURLSession for the network functionality seems like my best bet, but I'm confused as to how to use the two in tandem. I know I add instances of NSOperation to the NSOperationQueue and they get queued. And it seems I create a download

NSOperationQueue serial FIFO queue

末鹿安然 提交于 2019-11-26 18:18:42
问题 Is it possible to use an NSoperationQueue object as a serial FIFO queue by setting its maxConcurrentOperationCount to 1? I note that the docs state... For a queue whose maximum number of concurrent operations is set to 1, this equates to a serial queue. However, you should never rely on the serial execution of operation objects. Does this mean that FIFO execution is not guaranteed? 回答1: In most cases, it will be FIFO. However, you can set up dependencies between NSOperations such that an

Subclassing NSOperation to be concurrent and cancellable

a 夏天 提交于 2019-11-26 12:35:09
问题 I am unable to find good documentation about how to subclass NSOperation to be concurrent and also to support cancellation. I read the Apple docs, but I am unable to find an \"official\" example. Here is my source code : @synthesize isExecuting = _isExecuting; @synthesize isFinished = _isFinished; @synthesize isCancelled = _isCancelled; - (BOOL)isConcurrent { return YES; } - (void)start { /* WHY SHOULD I PUT THIS ? if (![NSThread isMainThread]) { [self performSelectorOnMainThread:@selector

NSOperation and NSOperationQueue working thread vs main thread

前提是你 提交于 2019-11-26 07:53:32
问题 I have to carry out a series of download and database write operations in my app. I am using the NSOperation and NSOperationQueue for the same. This is application scenario: Fetch all postcodes from a place. For each postcode fetch all houses. For each house fetch inhabitant details As said, I have defined an NSOperation for each task. In first case (Task1), I am sending a request to server to fetch all postcodes. The delegate within the NSOperation will receive the data. This data is then

NSOperation vs Grand Central Dispatch

。_饼干妹妹 提交于 2019-11-26 00:38:53
问题 I\'m learning about concurrent programming for iOS. So far I\'ve read about NSOperation/NSOperationQueue and GCD. What are the reasons for using NSOperationQueue over GCD and vice versa? Sounds like both GCD and NSOperationQueue abstract away the explicit creation of NSThreads from the user. However the relationship between the two approaches isn\'t clear to me so any feedback to appreciated! 回答1: GCD is a low-level C-based API that enables very simple use of a task-based concurrency model.