title: iphone cocoa use of nsrunloop
body: <p>I find myself using a combination of global vars and nsrunloop to force synchronization throughout my application.  Although it works it seems a bit ugly to me.  Is there any other way of achieving the same result?  </p>
  
  <p>Here's a typically example:</p>
  
  <pre><code>ParkingSpots *parkingSpots = [[[ParkingSpots alloc] initWithMapViewController:self] autorelease];
          keepRunning = YES;
          NSRunLoop *theRL = [NSRunLoop currentRunLoop];
          while (keepRunning &amp;&amp; [theRL runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]);
  
          UpdateLocation *updatedLocation = [[[UpdateLocation alloc] initWithUserid:@"me" andCoordinate:annotation.coordinate withMapViewController:self]
                                             autorelease];
          NSLog(@"Lat = %f, Long = %f",annotation.coordinate.latitude,annotation.coordinate.longitude);
          [updatedLocation sendUpdate];
  </code></pre>
  
  <p>In this code I need to wait until the parkingSpots object is completely initialized before I initialize updateLocation.  Since updatelocation expects parkingSpots to be fully initialized, without the runloop updatedlocation was not initializing properly.  WIth the runloop everything works as expected.  </p>
  
  <p>However this looks very ugly to me (setting a global var at various points in my code).  Is there a more elegant solution?  Thanks in advance for your help!</p>