joffd joffd - 6 months ago 39
Objective-C Question

Will code wait for return before continuing?

I using the below code to set elements in an array and return the array, the returned array is then passed to another method for more changes before again being returned.

NSMutableArray *returnArray = [[NSMutableArray alloc]init];

//call checkTP1
returnArray = [self checkTP1STD:addingTime :startToTP1 :TP1Result :nowDate :sevenHour :totalrest :returnArray];

//call check TP2
returnArray = [self checkTP2STD:addingTime :startToTP2 :TP2Result :nowDate :sevenHour :totalrest :returnArray :tp2Rest];

It is currently working as expected, my question is will it always wait for the checkTP1STD to return before executing checkTP2STD?

I have split the code into multiple methods to enable it to be more readable as i will be adding some other logic to pass different variable values to the methods,just wanted to make sure my basic idea will work.


In general: yes

Your question is curious, you seem to be concerned that checkTP1STD will return before checkTP2STD is called, but not that the calls to alloc and init will return before the call to checkTP1STD.

Are you actually intending to do asynchronous work in checkTP1STD (E.g. Using GCD or system framework methods which state they are async). If so the answer is still yes, but the call may return before all the work scheduled by checkTP1STD is complete - the very nature of asynchronous programming.