block 影响代码执行由上往下执行顺序 从而影响功能的解决
其实 就是 多线程 或者线程锁 当然可能会有人用监听,这里只是给一种解决办法 嘿嘿
- (CLPlacemark*)getStartplacemark
{
//先创建一个semaphore
dispatch_queue_t queue = dispatch_get_global_queue(0, 0);
dispatch_semaphore_t semaphore = dispatch_semaphore_create(1);
__block CLPlacemark* start;
[self.geoCoder geocodeAddressString:_SourceText.text completionHandler:^(NSArray *placemarks, NSError *error) {
CLPlacemark *startPlaceMark = [placemarks firstObject];
start = startPlaceMark;
//发出已完成的信号
dispatch_semaphore_signal(semaphore);
}];
//等待执行,不会占用资源
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
return start;
}