I want to wrap an async API that look like this:
[someObject completeTaskWithCompletionHandler:^(NSString *result) {
}];
into a synchronous m
I think the better solution will be NSRunLoop as given below. It's simple and working fine.
- (NSString *)getValue {
__block BOOL _completed = NO;
__block NSString *mValue = nil;
[self doSomethingWithCompletionHandler:^(id __nullable value, NSError * __nullable error) {
mValue = value;
_completed = YES;
}];
while (!_completed) {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
}
return mValue;
}