nsoperation

how to cancel out of operation created with addOperationWithBlock?

主宰稳场 提交于 2019-11-30 06:55:39
问题 I'm using NSOperationQueue's addOperationWithBlock. From within the block, how do I check to see if I'm supposed to cancel the operation? Or access any NSOperation properties/methods? [myOperationQueue addOperationWithBlock: ^{ while ( /* long running loop */ ) { // how to determine here if I need to cancel? // for that matter, access any NSOperation properties/methods? } }]; Is the better way to do this to use a NSBlockOperation? 回答1: A better solution might be to use NSBlockOperation and

Waiting for completion block to complete in an AFNetworking request

假如想象 提交于 2019-11-30 05:34:47
I am making a JSON request with AFNetworking and then call [operation waitUntilFinished] to wait on the operation and the success or failure blocks. But, it seems to fall right though - in terms of the log messages, I get "0", "3", "1" instead of "0", "1", "3" NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://google.com"]]; AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url]; httpClient.parameterEncoding = AFFormURLParameterEncoding; NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:@"query", @"q", nil]; NSMutableURLRequest *request =

Core Data/NSOperation: crash while enumerating through and deleting objects

纵然是瞬间 提交于 2019-11-30 03:32:31
问题 I have a core data based app that has a one object (a list) to many objects (list items) relationship. I'm working on syncing data between devices, and as part of that I import lists from XML files in background threads (via an NSOperation subclass). When I'm updating an existing list, I delete all of its old list items (from the NSManagedObjectContext specific to that thread) and replace them with new ones from the XML file... the delete is handled by enumerating through the items for that

Asynchronous url requests inside dispatch_async

女生的网名这么多〃 提交于 2019-11-30 02:29:40
I am trying to implement asynchronous url requests in a particular function, I want all these requests to complete and then do a particular action but the action precedes the requests i.e, it is getting called before the requests complete. dispatch_queue_t fetchQ = dispatch_queue_create("Featured Doc Downloader", NULL); dispatch_async(fetchQ, ^{ [self myAsyncMultipleURLRequestFunction]; dispatch_sync(dispatch_get_main_queue(), ^{ [self updateUIFunction]; }); }); -(void)myAsyncMultipleURLRequestFunction { for (int i=0; i<count; i++) { NSURLConnection *loginConnection = [[NSURLConnection alloc]

Difference between performSelectorInBackground and NSOperation Subclass

女生的网名这么多〃 提交于 2019-11-29 22:14:55
问题 I have created one testing app for running deep counter loop. I run the loop function in background thread using performSelectorInBackground and also NSOperation subclass separately. I am also using performSelectorOnMainThread to notify main thread within backgroundthread method and [NSNotificationCenter defaultCenter] postNotificationName within NSOperation subclass to notify main thread for updating UI. Initially both the implementation giving me same result and i am able to update UI

NSOperation property overrides (isExecuting / isFinished)

怎甘沉沦 提交于 2019-11-29 21:00:51
I am subclassing NSOperation in Swift and need to override the isExecuting and isFinished properties since I am overriding the start method. The problem I run into is how to preserve key-value observing (KVO) while also being able to override these properties. Normally in Obj-C this would be rather easy to redeclare the properties as readwrite in the class extension JSONOperation () definition. However, I don't see this same capability in Swift. Example: class JSONOperation : NSOperation, NSURLConnectionDelegate { var executing : Bool { get { return super.executing } set { super.executing } //

How to subclass NSOperation in Swift to queue SKAction objects for serial execution?

拟墨画扇 提交于 2019-11-29 14:32:09
Rob provided a great Objective-C solution for subclassing NSOperation to achieve a serial queuing mechanism for SKAction objects. I implemented this successfully in my own Swift project. import SpriteKit class ActionOperation : NSOperation { let _node: SKNode // The sprite node on which an action is to be performed let _action: SKAction // The action to perform on the sprite node var _finished = false // Our read-write mirror of the super's read-only finished property var _executing = false // Our read-write mirror of the super's read-only executing property /// Override read-only superclass

How to stop current NSOperation?

隐身守侯 提交于 2019-11-29 13:52:55
I'm using NSOperationQueue , and NSOperation for running some function on background click. But I want to be able, when user clicks some button, stop that Operation. How can I do it? Something like, [currentoperation stop]; Cancel - won't work me. I want to stop immediately. Thanks You should be calling the -cancel method, and the operation itself has to support being cancelled by monitoring the isCancelled property/keypath and safely stopping when its value becomes YES . If the NSOperation is your own, you will probably have to create a custom subclass to implement this functionality. You

How to immediately force cancel an NSOperation with AFNetworking?

只谈情不闲聊 提交于 2019-11-29 05:15:38
I am using AFNetworking in my application and I am attempting to implement a "Tap To Cancel" feature in my progress HUD. I have a singleton class that manages all of the HTTP requests. If the progress HUD is tapped, I call: [[[HTTPRequestSingleton sharedClient] operationQueue] cancelAllOperations]; But this doesn't "cancel" the operation like I need it to. I read up on the NSOperationQueue docs and came across this: Canceling an operation object leaves the object in the queue but notifies the object that it should abort its task as quickly as possible. For currently executing operations, this

Waiting for completion block to complete in an AFNetworking request

自作多情 提交于 2019-11-29 03:32:03
问题 I am making a JSON request with AFNetworking and then call [operation waitUntilFinished] to wait on the operation and the success or failure blocks. But, it seems to fall right though - in terms of the log messages, I get "0", "3", "1" instead of "0", "1", "3" NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://google.com"]]; AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url]; httpClient.parameterEncoding = AFFormURLParameterEncoding; NSDictionary *params