Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's true that obtaining the results of your web services calls are (and should be) asynchronous, however, you want your calls to happen in a sequence. One way would be to wait for the first one to finish before calling the second and post a notification when the first is done. So, in -connectionDidFinishLoading of your first request (in your webServiceCaller, I'm assuming), post a notification back to your controller telling it that the first request finished successfully. Something like:</p> <pre><code>- (void)connectionDidFinishLoading:(NSURLConnection *)connection { [connection release]; // receivedData is an NSMutableData object we've been appending // to in the -didReceiveData delegate. We'll pass it in the // notification so we can hand the data off to the next request. [[NSNotificationCenter defaultCenter] postNotificationName:kGetSummaryDidFinish object:receivedData]; } </code></pre> <p>Then, back in your controller, register for that notification:</p> <pre><code>- (void)viewDidLoad; { [super viewDidLoad]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getSummaryDidFinish:) name:kGetSummaryDidFinish object:nil]; } - (void) getSummaryDidFinish:(NSNotification*)notification; { // If you needed the downloaded data, we passed it in NSData *data = [notification object]; // Decide here if you want to call getList or not. if (someConditionOfDataObjectIsTrue) [webServiceCaller getList]; } </code></pre> <p>If you have a lot of calls that wait on each other like this, it can get pretty confusing and hard to maintain, so there may be a design pattern you should consider (not that one comes to mind at the moment). However, this method has worked pretty well for me. Notifications help it to make more sense as you can call all of your requests from your controller when you receive a notification that meets some criteria.</p> <p>Hope that makes sense.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload