nsoperationqueue

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

二次信任 提交于 2019-11-27 17:27:38
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 addOperation:invOperation]; Is there any reason to switch away from NSThread ? GCD is a 4th option when it's

NSOperationQueue serial FIFO queue

你说的曾经没有我的故事 提交于 2019-11-27 13:39:45
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? In most cases, it will be FIFO. However, you can set up dependencies between NSOperations such that an operation submitted early will let other operations pass it by in the queue until its dependencies are satisfied

NSOperationqueue background, download images

醉酒当歌 提交于 2019-11-27 13:18:40
问题 I created a NSOperationQueue to download images (from Twitter for Cell): NSOperationQueue *queue = [[NSOperationQueue alloc]init]; [queue addOperationWithBlock:^{ NSString *ImagesUrl = [[NSString alloc]initWithFormat:@"http://api.twitter.com/1/users/profile_image/%@",[[status objectForKey:@"user"]objectForKey:@"screen_name"]];; NSURL *imageurl = [NSURL URLWithString:ImagesUrl]; UIImage *img = [UIImage imageWithData:[NSData dataWithContentsOfURL:imageurl]]; [[NSOperationQueue mainQueue

NSAttributedString initWithData and NSHTMLTextDocumentType crash if not on main thread

∥☆過路亽.° 提交于 2019-11-27 13:14:36
问题 calling NSAttributedString * as = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUTF8StringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding)} documentAttributes:nil error:nil]; on other than main thread, results in a crash 1 0x194b861fc <redacted> 2 0x19801d31c <redacted> 3 0x198010eb4 _os_once 4 0x19801aa2c pthread_once 5 0x195a0858c <redacted> 6 0x195a07c78 WebKitInitialize 7

How do I use NSOperationQueue with NSURLSession?

余生长醉 提交于 2019-11-27 10:17:54
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 task with NSURLSessionDownloadTask , and multiple if I need multiple tasks, but I'm not sure how I put

(iOS) dispatch_async() vs. NSOperationQueue

限于喜欢 提交于 2019-11-27 09:14:42
问题 I learned iOS programming thanks to Stanford's CS193p course (on iTunes U) as well as the iOS programming book from Big Nerd Ranch. In both of those, they recommend using dispatch_async() , dispatch_get_main_queue() , etc. to handle threading and concurrent operations. However, at WWDC 2012's session on building concurrent UI, the speaker recommended the use of NSOperationQueue . What are the differences between dispatch_*() and NSOperationQueue , and is there any reason (technical,

Generic NSOperation subclass loses NSOperation functionality

99封情书 提交于 2019-11-27 08:44:51
Today I've met one weird issue when I was trying to 'generalize' my 'CoreData importing operations'. It appeared that if I create a generic subclass of NSOperation the main() func won't be called. Simple example: class MyOperation<T: NSObject>: NSOperation { override func main() { println("My operation main was called") } } If you create an instance of this class and add it to the operationQueue you will see that it's main() isn't actually called. override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. self.operationQueue =

Do NSOperations and their completionBlocks run concurrently?

送分小仙女□ 提交于 2019-11-27 07:03:18
问题 I've got a bunch of NSOperations added to a NSOperationQueue . The operation queue has the maxConcurrentOperationCount set to 1, so that the NSOperations run one after the other. Now, in the completionBlock of a NSOperation I want to cancel all pending NSOperations by calling cancelAllOperations on the NSOperationQueue . Is it safe to do this? Can I be sure that the start -method of the next operation is called only after the completionBlock of the previous operation has been fully executed?

How to cancel NSBlockOperation

江枫思渺然 提交于 2019-11-27 06:29:35
I have a long running loop I want to run in the background with an NSOperation . I'd like to use a block: NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{ while(/* not canceled*/){ //do something... } }]; The question is, how to I check to see if it's canceled. The block doesn't take any arguments, and operation is nil at the time it's captured by the block. Is there no way to cancel block operations? Doh. Dear future googlers: of course operation is nil when copied by the block, but it doesn't have to be copied. It can be qualified with __block like so: //THIS MIGHT

NSBlockOperation or NSOperation with ALAsset Block to display photo-library images using ALAsset URL

血红的双手。 提交于 2019-11-27 06:29:28
问题 I am asking this question regarding my questions Display photolibrary images in an effectual way iPhone and Highly efficient UITableView "cellForRowIndexPath" method to bind the PhotoLibrary images . So I would like to request that answers are not duplicated to this one without reading the below details :) Let's come to the issue, I have researched detailed about my above mentioned issue, and I have found the document about operation queues from here. So I have created one sample application