Program Control Methods

I am struggling with the concept of code "order of execution", and so far my research has been short. I am not sure if I am phrasing it incorrectly, perhaps there is a more suitable term for the concept. I would appreciate it if someone could shed light on my various stumbling blocks below.

I understand that if you call one method after another:

[self generateGrid1];
[self generateGrid2];

Both methods start, but generateGrid1 does not necessarily wait for generateGrid2. But what if I need it? Let's say generateGrid1 does some complex calculations (which take an unknown amount of time) and populates the array that generateGrid2 uses to compute it? This needs to be done every time an event is fired, it is not just a one-time initialization.

I need a way to call methods sequentially, but some methods are waiting for others. I was looking for callbacks, but the concept has always been married to delegates in all the examples I saw.

I am also not sure when to determine that I cannot reasonably expect a line of code to be parsed in time for its use. For instance:

int myVar = [self complexFloatCalculation];
if (myVar <= 10.0f) {} else {} 

How to determine if something will take a long enough time to perform checks on "This is another matter before I begin my work." Just trial and error?

Or maybe I'm passing a method as a parameter to another method? Wait until the arguments are evaluated before executing the method?

[self getNameForValue:[self getIntValue]];
+3
source share
2 answers

, , , , , , , , .

, , .

+5

, :

[self generateGrid1];
[self generateGrid2];

, generateGrid1 generateGrid2. , ?

False. generateGrid1 , generateGrid2. .

, , , - . , :

int x = 3;
int y = 4;

x = x + 6;
y = y - 1;

int z = x + y;
printf("z is %d", z);

, , x+6 y-1; , z, . , - , , .

, , (, ), , , , .

, ; , . , , , . , , , , , . .

, , , , . Objective-c , , , . , , Objective-c. , , : , .

, . , .
+6
source

All Articles