When working with Cocoa/Cocoa-Touch and the iPhone SDK, a typical convention is to build a client which speaks to a server-side web server. One common problem I face when programming is making multiple HTTP requests in sequence, sometimes up to 5-6 requests. The order in which the requests are made is not linear in which they will return. When a view is brought onto the window for which these requests are fired off, I have notifications using NSNotification letting me know when particular data is available. I’m mulling over an approach which would trigger my UI only when all the data sets are ready. Looking for good practice and insight into your approach. Are you using mutexes or something similar? Simple counters?
When working with Cocoa/Cocoa-Touch and the iPhone SDK, a typical convention is to build
Share
Assuming you know all the requests that need to be made, you could store the various request objects in an array (NSMutableArray). As you receive notifications for each request, pop it off the array. When your array length equals zero, you know that all your requests have completed. You’ll need to ensure that access to the array is guarded by mutexes. You’ll also need to ensure that you only fire off the requests after your array is populated (lest you get a notification before your 2nd request has been inserted into the array).
Another technique, is to make the HTTP requests in another thread (performSelectorInBackground: or performSelector:onThread:), but do them synchronously. This way you know exactly when all the requests have completed and can signal the UI to update itself.