nsoperationqueue

Fixing my network activity indicator

送分小仙女□ 提交于 2019-12-12 09:55:32
问题 I have a problem with my network activity indicator in that sometimes it will continue to be displayed when it should not be. I wrote my own manager for it and swapped it out for one that uses an NSAssert statement like this... - (void)setNetworkActivityIndicatorVisible:(BOOL)setVisible { static NSInteger NumberOfCallsToSetVisible = 0; if (setVisible) NumberOfCallsToSetVisible++; else NumberOfCallsToSetVisible--; // The assertion helps to find programmer errors in activity indicator

Download images in order with AFNetworking

試著忘記壹切 提交于 2019-12-12 05:17:50
问题 How do you download images in order with AFNetworking? An by "in order", I also mean executing the success blocks in order. Initially I thought it would be enough to use a NSOperationQueue and set each AFImageRequestOperation as a dependency of the next one. Like this: - (void) downloadImages { { // Reset [_downloadQueue cancelAllOperations]; _downloadQueue = [[NSOperationQueue alloc] init]; _images = [NSMutableArray array]; } AFImageRequestOperation *previousOperation = nil; for (NSInteger i

How to trigger NSOperationQueue and get results in block of multiple operation

◇◆丶佛笑我妖孽 提交于 2019-12-12 02:54:30
问题 I already asked question related to NSOperationQueue but I am still around of implementing operation queue with multiples operation. I have following code NSMutableArray * operationArray = [[NSMutableArray alloc] init]; for (int i =0; i<[documentModelList count]; i++) { DocumentModel * documentModel = [documentModelList objectAtIndex:i]; NSString *url = [NSString stringWithFormat:@"%@%@/%li", SERVER_URL, DOCUMENTS_DELETE,(long)documentModel.documentID]; [operationArray addObject:

NSOperation KVO problem

拈花ヽ惹草 提交于 2019-12-11 18:25:21
问题 I'm using following function to get my application notified after the operation in nsoperationqueue has finished, so that I can schedule the task that's dependent upon the result of the operation. I'm using: - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { if([keyPath isEqual:@"isFinished"] && _operation == object) { NSLog(@"Our Thread Finished!"); [_operation removeObserver:self forKeyPath:@"isFinished"]; [self

NSOperationQueue seems to slow performance

南笙酒味 提交于 2019-12-11 18:24:35
问题 I am new to NSOperationQueue, but in a current project I need a way to cancel an asynchronous operation when it times out. My original code uses GCD and works. Here it is: dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0),^{ rg = [[RiverGauge alloc] initWithStationInfo:[station id] forHistoryInHours:48 inThisFormat:nil]; dispatch_async(dispatch_get_main_queue(), ^{ [hud removeFromSuperview]; UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

creating UI elements on NSOperationQueue non-main queues causes strange behavior

自作多情 提交于 2019-12-11 14:22:38
问题 I had some code that created and added UIView subviews via a queue created by [[NSOperationQueue alloc] init] , and it led to strangely laggy behavior. Subviews were only added after abnormally long delays. But then I switched to using [NSOperationQueue mainQueue] for these parts, and responsiveness turned normal. I would just like an explanation for the laggy behavior I saw using the first approach. 回答1: From Apple doc Threads and Your User Interface If your application has a graphical user

NSOperation with completition block

♀尐吖头ヾ 提交于 2019-12-11 08:35:11
问题 I have some image processing that take much time and resources, so i use NSOperation + NSOperatioQueue + delegate for callBack. and all work. now i want to use blocks because its much elegant and simple to use in a tableView for example. what i need to do is just like AFJSONRequestOperation for example: NSURL *url = [NSURL URLWithString:@"url"]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; AFJSONRequestOperation *operation = [AFJSONRequestOperation

NSOperation mainQueue issue

独自空忆成欢 提交于 2019-12-11 05:48:28
问题 I have slideshow, and I want to show Big images, I added to [NSOperation mainQueue] operation with low priority, this operation shows the image. If image is small , everything is OK, but when image is about 5Mb, the view freeze for 1 second, and I can't scroll my slideshow. I think, that displaying big images just so difficult for iPhone, that main queue is too overloaded. But I don't inderstand it , because all my displaying code is executed in low priority operation. Here is the displaying

Thread safety: NSOperationQueue + [array addObject]

十年热恋 提交于 2019-12-11 05:15:35
问题 I could not find any examples how to deal with the same (class) variable when operation queue is used. In C & threads its about mutexes. So, what happens when NSOperationQueue starts a thread for operation and class variable is modified? Is it thread safe? Thank you. @interface MyTest { NSMutableArray *_array; } @end -(id)init { ... _array = [NSMutableArray new]; // class variable // queue time consuming loading NSOperationQueue *queue = [NSOperationQueue new]; NSInvocationOperation

Cancel NSOperation From NSOperationQueue

寵の児 提交于 2019-12-11 04:34:20
问题 I have downloaded information from an url, and I am sending this url as NSOperation in an NSOperationQueue, I want to know, how I can delete a specific NSOperation to download data for a specific url, now I am doing in this way: AppDelegate *appController = (AppDelegate *) [[UIApplication sharedApplication] delegate]; for (NSOperation *op in appController.seriesQueue.operations) { if ([op isKindOfClass:[MyDowndload class]]) { MyDownload *urlInDownload = (MyDowndload *)op; if ([urlInDownload