자신이 글로벌 vars와 nsrunloop의 조합을 사용하여 응용 프로그램 전체에 강제로 동기화하는 것을 발견했습니다. 그것은 작동하지만 그것은 나에게 약간 못 생겼습니다. 동일한 결과를 얻는 다른 방법이 있습니까?iphone 코코아 nsrunloop 사용
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];
내가 updateLocation를 초기화하기 전에 parkingSpots가 완전히 초기화 객체 때까지 기다릴 필요가이 코드에서 :
다음은 전형적인 예입니다. updatelocation은 parkingPoint가 완전히 초기화되기를 기대하기 때문에 runloop의 updatedlocation이 제대로 초기화되지 않았습니다. runloop을 사용하면 모든 것이 예상대로 작동합니다.
그러나이 코드는 내 코드의 여러 지점에서 전역 변수를 설정하는 것이 매우 못 생겼습니다. 보다 우아한 솔루션이 있습니까? 도와 주셔서 미리 감사드립니다.
@Nathan 제안에 감사드립니다. 알림 사용에 관해서는 설명하지만 구현 방법에 대해서는 조금 혼란 스러웠습니다. 약간의 의사 코드 (psuedocode)를 게시하여 그 사실을 분명히 알 수 있다고 생각하십니까? 미리 감사드립니다! – ennuikiller
감사합니다. nsnotifications를 사용했고 그 작업은 훌륭했습니다 !! – ennuikiller