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?
Here's a typically example:
ParkingSpots *parkingSpots = [[[ParkingSpots alloc] initWithMapViewController:self] autorelease];
keepRunning = YES;
NSRunLoop *theRL = [NSRunLoop currentRunLoop];
while (keepRunning && [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];
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.
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!