Using Grand Central Dispatch on iOS, what queue (if any) do regular Objective-C blocks run on if they are not in a dispatch queue? -


Do the options # 1 run some sort of inherent queue below? It does not seem to run on the main line, because when I tried updating the AI ​​content, I complained, till I did not run in option # 3, I believe the blocks have their own queue or thread is? Before complaining, I was under the assumption that if I did not start a dispatch queue that things would run like normal, which would be in the main line in my mind, for example examples of example:

  // user view controller. @ Interface user view controller: NSObject @property (nonatomic, strong) server * server; @protecti (non-standard, strong) user * user; @end // UserViewController.m - The controller that sets a block to be used in the other category @UfLuleUserUser controller - (zero) doSomething {// I want to call other methods and set the property @ from the controller and I have heard / / __weak is the right keyword to use (rather than __block or __strong). __weak UserViewController * Vulnerable Controller = Self; // Option # 0 - controller outside the block weakening. User = [[RHJUSAR Alok] Init]; Server.callbackBlock = ^ (NSURLResponse * response, NSData * data, NSError * error) {// Option # 1 - Is it in some sort of default queue outside the send queue? WeakController.user = [[RHAGUSAR Alok] Init]; Dispatch_queue_t background Queue = dispatch_queue_create ("com.example.backgroundQueue", null); Sender_Associate (background que, ^ {// option # 2 - this is in serial queue which I have weakened Controller User. [[RHZ User Alloc] init]; Dispatch_Assic (Dispatch_Get_man_QE), ^ {// Option # 3 - Main Queue All my UI is weak controller User = [[[RHJJASArAlok] Init];} // Dispatch_Asslicator} // Dispatch_Association}; // Speak Block Lock; @ and // serverM - A version using block defined in controller @ Implementation Server - makeAServerCall {[NSURLConnection sendAsynchronousRequest: [NSMutableURLRequest requestWithURL: restServiceURL] Queue: [[NSOperationQueue alloc] init] completionHandler: self.callbackBlock];} @end    

< P> In the case of option 1, you set block properties at a frequency of server . It's not that for running, all those who make the code accessible to anyone with access to that block. Because the name of the property is callbackBlock , I think the server example completes the block when it finishes something.

It When the block is tied to a line. Implementation of the server determines whether it runs on the main line or not, and whether the document (maybe its in), whether or not it is not documented, but it is completely Need to run on the main line, so I always keep it safe and ensure that this is a main code wrapped in dispatch_async . Edit:

Belongs to your server implementation is similar to server You create a new queue alloc / init and pass it to NSURLConnection . From NSURL connection Documentation:

queue

Operation queue on which the handler block sends requests to the full or unsuccessful.

Therefore, the behavior is actually documented and if you want the handler to be called in the main line, then simply pass dispatch_get_main_queue .

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -