간단한 문제가 있습니다 ... 솔루션이 간단하기를 바랍니다. 블록 내부비동기 실행 블록이 완료 될 때까지 기다리는 중
__block NSString * response; //the result !
[deviceInfo.geocoder reverseGeocodeLocation:deviceInfo.locationProperties completionHandler:
^(NSArray *placemarks, NSError *error) {
[placemarks copy];
//Get nearby address
CLPlacemark *placemark = [placemarks objectAtIndex:0];
NSLog(@"Country : %@",placemark.country);
response =placemark.country;
}
];
//-----------------------------------------------
NSLog(@"Response COUNTRY : %@",response); // response = NULL /!\
, placemark.country
이 UK
같음 :
여기 내 코드입니다.
블록 외부에서 response = placemark.country
을 어떻게 가질 수 있습니까?
및 블록이 실제로 호출 될 때까지 그래서'response'은 채워되지 않습니다. (a) 코드의 동기 실행에 대해 알아야합니다. – trojanfoe
그러면 비동기 메서드가 끝날 때까지 기다릴 수 있습니까? – Patatrack
기다리는 동안 다른 작업을 수행하여 블록에서 결과 중 하나를 호출하면 UI를 업데이트하거나 수행 할 작업 목록에서 다음 작업을 수행 할 수 있습니다. – trojanfoe