nsoperation

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];

iPhone - return from an NSOperation

蓝咒 提交于 2019-12-11 14:45:24
问题 I am using a subclass of NSOperation to do some background processes. I want the operation to be cancelled when the user clicks a button. Here's what my NSOperation subclass looks like - (id)init{ self = [super init]; if(self){ //initialization code goes here _isFinished = NO; _isExecuting = NO; } return self; } - (void)start { if (![NSThread isMainThread]) { [self performSelectorOnMainThread:@selector(start) withObject:nil waitUntilDone:NO]; return; } [self willChangeValueForKey:@

Cancel NSData initWithContentsOfURL in NSOperation

为君一笑 提交于 2019-12-11 13:27:26
问题 I currently have the following code in an NSOperation that has an observer for keyPath "isCancelled": downloaded = FALSE; NSURL *url = [NSURL URLWithString:requestString]; dataXML = [[NSData alloc] initWithContentsOfURL:url]; downloaded = TRUE; I want to make it so that the observeValueForKeyPath function is able to cancel the dataXML continuing or just completely stop the NSOperation once the NSOperation is sent a cancel message. The NSOperation's cancelling operation cancel only notifies

What would be a thread-safe way to save a context form Core Data?

耗尽温柔 提交于 2019-12-11 12:47:14
问题 I have a NSOperationQueue set to NSOperationQueueDefaultMaxConcurrentOperationCount . It is filled with NSOperation objects (nothing weird so far). I subclassed the NSOperation to do some background tasks. Download data from the internet. Parse the data so I can read it. Create a NSManagedObject: [NSEntityDescription insertNewObjectForEntityForName:@"Channel" inManagedObjectContext:context]; Save it with the context. [managedObjectContext save:&error] I like this all to happen in the

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

EXC_BAD_ACCESS crash when updating NSManagedObject

非 Y 不嫁゛ 提交于 2019-12-11 06:25:30
问题 I have an application that pulls JSON data from a server, parses the data into NSManagedObject subclasses and these NSManagedObject subclasses are then used as properties in various view controllers. The trouble I'm having is that at some point in the future the data on the server will change and this will trigger an update pull request. When attempting to update the NSManagedObject subclasses, the app is crashing if the user then attempts to modify NSManagedObject via the UI by e.g.

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

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

GCDAsyncSocket “didReadDataWithTag” Never called with NSOperation subclass

最后都变了- 提交于 2019-12-11 03:28:32
问题 In a "getMyFile" method of some XIB file. I am creating a object of class "A"(subclass of NSOperation) and adding it to a "myFileQueue"(object of NSOperationQueue). myFileQueue.MaxConcurrentOperationCount = 1; Problem : didReadDataWithTag" delegate NEVER called in any case. #import "GCDAsyncSocket.h" //and all other required classes are imported correctly //Class : A @interface A : NSOperation { { GCDAsyncSocket* socket; dispatch_queue_t dQueue; BOOL isWorkDone; } } @implementation A { -main(