Note that there are some explanatory texts on larger screens.

plurals
  1. POis it necessary to use dispatch_queue at here
    text
    copied!<p>Hopefully it is an appropriate question to ask. My goal is </p> <pre><code>1.add a controller into an array name 'arrControllers' 2.access and get current controller from 'arrControllers' to do sth with it </code></pre> <p>and I just wanna make sure the <code>arrControllers</code> should be ready before I access and use it. That is why I am using <code>serial queue</code> and <code>dispatch_sycn</code> like like following.</p> <pre><code>-(void)viewDidLoad { [super viewDidLoad]; firstViewController = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil]; [self setUpWithView:firstViewController]; } </code></pre> <p>and in <code>setUpWithView:</code> is</p> <pre><code>-(void)setUpWithView:(UIViewController*)viewController { dispatch_queue_t queue; queue = dispatch_queue_create("my queue", NULL); containerController = [ContainerViewController sharedContainerController]; // What I am taking about is from now on dispatch_sync(queue, ^{ [containerController initWithRootViewController:viewController]; }); dispatch_sync(queue, ^{ [containerController setUpView]; }); } </code></pre> <p>and <code>initWithRootViewController:</code> is</p> <pre><code>- (void)initWithRootViewController:(UIViewController*)rootViewController { arrControllers = [[NSMutableArray alloc] init]; arrControllers = [NSMutableArray arrayWithObject:rootViewController]; } </code></pre> <p>and <code>setUpView</code> is</p> <pre><code> -(void)setUpView { /* Process to ADD currentController TO hierarchy */ [self addChildViewController:[arrControllers lastObject]]; ............................................................ } </code></pre> <p>As far as I know the compiler will execute codes line by line, it means by do following</p> <pre><code>-(void)setUpWithView:(UIViewController*)viewController { containerController = [ContainerViewController sharedContainerController]; // Not using serial_queue and dispatch_sync [containerController initWithRootViewController:viewController];// line1 [containerController setUpView]; //line2 } </code></pre> <p>compiler will execute line2 until it finished the task at line1.</p> <p>My question is </p> <pre><code>1. is it necessary to using `serial_queue` and `dispatch_sycn`for this situation. </code></pre> <p>PS: if you think it is a bad question to ask. please comment what you think about it.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload