nsoperationqueue

iOS - How to check if an NSOperation is in an NSOperationQueue?

两盒软妹~` 提交于 2019-12-04 23:22:38
问题 From the docs: An operation object can be in at most one operation queue at a time and this method throws an NSInvalidArgumentException exception if the operation is already in another queue. Similarly, this method throws an NSInvalidArgumentException exception if the operation is currently executing or has already finished executing. So how do I check if I can safely add an NSOperation into a queue? The only way I know is add the operation and then try to catch the exception if the operation

ios NSOperationQueue, operations all run when added and don't queue

会有一股神秘感。 提交于 2019-12-04 20:58:21
So, I have a group of ASINetworkQueues that currently run together resulting in a race condition when it comes to DB saves. I am trying to create an NSOperationQueue that will will queue each of these "sub queues". I currently have created an NSOperation with a main method that kicks off the "sub queue" to start it's download. My problem is that each time I add a sub queue to the main queue using "addOperation" it fires that "main" method straight away so my sub queues run concurrently. I was under the impression the main method was fired one at a time. i.e. only for the operation at the top

How to make simultaneous https requests in Swift 3

蓝咒 提交于 2019-12-04 17:29:36
I'm having problems to execute a https requests, if the request don't have any error i never get the message, this is a command line tool application and i have a plist to allow http requests, i always see the completion block. typealias escHandler = ( URLResponse?, Data? ) -> Void func getRequest(url : URL, _ handler : @escaping escHandler){ let session = URLSession.shared var request = URLRequest(url:url) request.cachePolicy = .reloadIgnoringLocalCacheData request.httpMethod = "GET" let task = session.dataTask(with: url ){ (data,response,error) in handler(response,data) } task.resume() }

[NSOperation cancelAllOperations]; does not stop the operation

谁说胖子不能爱 提交于 2019-12-04 16:25:44
问题 xCode 4.4.1 OSX 10.8.2, looks like [operation cancelAllOperations]; isn't working - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { NSOperationQueue *operation = [[NSOperationQueue alloc] init]; [operation setMaxConcurrentOperationCount: 1]; [operation addOperationWithBlock: ^{ for (unsigned i=0; i < 10000000; i++) { printf("%i\n",i); } }]; sleep(1); if ([operation operationCount] > 0) { [operation cancelAllOperations]; } } results 9999999 回答1: Inside your block,

Using a single shared background thread for iOS data processing?

本小妞迷上赌 提交于 2019-12-04 12:57:35
问题 I have an app where I'm downloading a number of resources from the network, and doing some processing on each one. I don't want this work happening on the main thread, but it's pretty lightweight and low-priority, so all of it can really happen on the same shared work thread. That seems like it'd be a good thing to do, because of the work required to set up & tear down all of these work threads (none of which will live very long, etc.). Surprisingly, though, there doesn't seem to be a simple

How to cancel NSOperationQueue

梦想的初衷 提交于 2019-12-04 12:42:24
Wondering if I'm implementing the below method correctly because isCancelled is not canceling the thread. I have an image that I'm scaling, and when it's done scaling, this method is called to update the image. So when the user lifts their finger off the button, this is called. If they try to push the button again before this is finished, I call cancelAllOperations on the queue but it's not working. Not even sure if cancelAllOperations triggers a flag, or if I need to keep calling it to get a result. Anyone have any insight on this? - (void) refreshImage { NSBlockOperation *operation = [

iOS App Architecture with NSOperations

笑着哭i 提交于 2019-12-04 08:17:02
问题 Two month ago I started to write a new iPhone Application and for this reason I created a generic RESTFul web service, which allows me to have a lot of these necessary features like user authentication, user profiles, a friendship system, media processing, a messaging system and so on. In my mind there are several use cases to reuse this webservice for future iPhone applications. With this state of mind, I decided to write a static library for this application (and all future apps) that

Can I cancel a Block added to an NSOperationQueue with addOperationWithBlock:?

淺唱寂寞╮ 提交于 2019-12-04 03:17:52
问题 I've read many many articles which say "BLOCKS ARE THE FUTURE!!!". I'm wondering if it relates to running operations in the background. For example, I have a table view which has images that will come from the web. Right now I can get them using +[NSOperationQueue addOperationWithBlock:] . An operation gets sent to the queue when the cell becomes visible. But is there a way to cancel it once the cell gets scrolled off the screen? Or is the only way to do it to subclass NSOperation ? Using

dispatch_after equivalent in NSOperationQueue

拜拜、爱过 提交于 2019-12-03 23:19:01
I'm moving my code from regular GCD to NSOperationQueue because I need some of the functionality. A lot of my code relies on dispatch_after in order to work properly. Is there a way to do something similar with an NSOperation ? This is some of my code that needs to be converted to NSOperation . If you could provide an example of converting it using this code, that would be great. dispatch_queue_t queue = dispatch_queue_create("com.cue.MainFade", NULL); dispatch_time_t mainPopTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(timeRun * NSEC_PER_SEC)); dispatch_after(mainPopTime, queue, ^(void){

NSOperationQueue - Getting Completion Call Too Early

帅比萌擦擦* 提交于 2019-12-03 21:50:52
I am using a NSOperationQueue to queue and call a number of Geocoding location lookups. I want to call a completion method when all asynchronicly running lookups have been finished. -(void)geocodeAllItems { NSOperationQueue *geoCodeQueue = [[NSOperationQueue alloc]init]; [geoCodeQueue setName:@"Geocode Queue"]; for (EventItem *item in [[EventItemStore sharedStore] allItems]) { if (item.eventLocationCLLocation){ NSLog(@"-Location Saved already. Skipping-"); continue; } [geoCodeQueue addOperationWithBlock:^{ NSLog(@"-Geocode Item-"); CLGeocoder* geocoder = [[CLGeocoder alloc] init]; [self