How to verify that the dispatch_async block is complete

So basically I need to be able to run segue after the block completes. I have a block that does some JSON stuff, and I need to know when it will end.

I have a queue that I called json_queue.

jsonQueue = dispatch_queue_create("com.jaboston.jsonQueue", NULL); 

Then I have a dispatch_async block with this syntax:

  dispatch_async(jsonQueue, ^{ [self doSomeJSON]; [self performSegueWithIdentifier:@"modaltomenu" sender:self]; }); 

This will not allow me to execute the line: "[self performSegueWithIdentifier: @" modaltomenu "sender: self];

I tried to get a web lock from a stream other than the main stream or web stream. This may be the result of calling UIKit from the secondary stream. Crash now ...

Where can I check when a thread has done its dirty work so that I can name segue?

Thank you, dear people.

PS: beer and ups and teddy bears and flowers to someone who can help <3.

+6
source share
2 answers

You should only call user interface methods in the main thread. Try sending performSegueWithIdentifier: in the main queue:

 dispatch_async(jsonQueue, ^{ [self doSomeJSON]; dispatch_sync(dispatch_get_main_queue(), ^{ [self performSegueWithIdentifier:@"modaltomenu" sender:self]; }); }); 
+26
source
  dispatch_async(jsonQueue, ^{ [self doSomeJSON]; dispatch_async(dispatch_get_main_queue(), ^{ [self performSegueWithIdentifier:@"modaltomenu" sender:self]; //Finished with async block }); }); 
+5
source

Source: https://habr.com/ru/post/920842/


All Articles