-(void) test{
for(Person *person in persons){
__block CGPoint point;
dispatch_async(dispatch_get_main_queue(), ^{
point = [self.myview personToPoint:person];
});
usePoint(point); // take a long time to run
}
}
I need to run personToPoint()
in the main queue to get the point, and usePoint()
method doesn't need to run in main queue and take a long time to run. However, when running usePoint(point)
, point has not been assigned value because using dispatch_async. If using dispatch_sync method, the program will be blocked. the how can I using point after it has been assigned?
UPDATE: how to implement the pattern of the following code:
-(void) test{
NSMutableArray *points = [NSMutableArray array];
for(Person *person in persons){
__block CGPoint point;
dispatch_async(dispatch_get_main_queue(), ^{
point = [self.myview personToPoint:person];
[points addObject:point];
});
}
usePoint(points); // take a long time to run
}