views:

41

answers:

1

I have create a class MyConnection that extends NSURLConnection. I have implemented some delegate methods. I am able to print the data received from the URL call. However when I pass the MyConnection instance into MyHelper class, I do not get the data received in the MyConnection class. I tried putting a sleep call between the two task and still no luck. connectionDidFinishLoading delegate method is called only after the current code block is finished. Is there a way to handle this issue without getting into notification?

MyConnection *con = [[MyConnection alloc] init];    
[con fetchDataFromServer];
//sleep call here
MyHelper *myHelper = [[MyHelper alloc ] initWithConnection:con];
[myHelper processDataFoundInConnection];
+2  A: 

That's because NSURLConnection (by default) processes asynchronously on the current runloop (so it's not asynchronous in that it doesn't use a secondary thread). So you can either spin the runloop manually or use the sendSynchronousRequest:... method.

Dave DeLong