Ok, This may be a very simple question to ask with a very obvious answer but I'm a little stuck on the best way to solve this problem.
I am coding an objective-c application using the iPhone SDK. I have some custom objects. These objects execute an NSURL request and send data to a web server, retrieve data back and move on.
My problem is that I have an initial request going to the server where I am authenticating. This request if successful returns some information for a session that I will use in the following request. If I want my application on start up to authenticate and then make an initial subsequent request I need the data from the first to perform the second. My problem is that in objective-c when I send a message to the request object to execute the request and return data to a variable as a result; the language by nature continues executing my method while the first request is in process. My second request can never be successful due to the first one not having returned data yet.
I don't remember what this is called but It is something in the line of running procedural code, single threaded code versus parallel processing or something.
What is the best way to hold my method's execution until the object that is sending the web request gets it's return value?
I am sure there are a few ways of doing this but I'm looking for what would be considered 'proper'.
Example sudo code below.
//First Request is sent obtaining some data that we will soon manipulate
MyClient *client = [[MyClient alloc] init];
NSString *returnData = [MyClient runRequest];
//Call an object that now plays with the data and does some neat things
CustomObject *CustomObj = [[CustomObject alloc] init];
[CustomObj dealWithResponse:returnData];
//Problem is now when I process the return data, it hasn't completed the first request from line 2 yet