Techniques for controlling program order of execution
arrays, design-patterns, objective-c, oop
Solution
In general, most method calls that you see in the style you described are synchronous, that means they'll have the effect you desire, running in the order the statements were coded, where the second call will only run after the first call finishes and returns.
Also, when a method takes parameters, its parameters are evaluated before the method is called.
Problem
I'm wrestling with the concept of code "order of execution" and so far my research has come up short. I'm not sure if I'm phrasing it incorrectly, it's possible there is a more appropriate term for the concept. I'd appreciate it if someone could shed some light on my various stumbling blocks below. I understand that if you call one method after another: ``` [self generateGrid1]; [self generateGrid2]; ``` Both methods are run, but generateGrid1 doesn't necessarily wait for generateGrid2. But what if I need it to? Say generateGrid1 does some complex calculations (that take an unknown amount of time) and populate an array that generateGrid2 uses for it's calculations? This needs to be done every time an event is fired, it's not just a one time initialization. I need a way to call methods sequentially, but have some methods wait for others. I've looked into call backs, but the concept is always married to delegates in all the examples I've seen. I'm also not sure when to make the determinate that I can't reasonably expect a line of code to be parsed in time for it to be used. For example: ``` int myVar = [self complexFloatCalculation]; if (myVar <= 10.0f) {} else {} ``` How do I determine if something will take long enough to implement checks for "Is this other thing done before I start my thing". Just trial and error? Or maybe I'm passing a method as parameter of another method? Does it wait for the arguments to be evaluated before executing the method? ``` [self getNameForValue:[self getIntValue]]; ```