Convert async block to sync

Since iOS 5, many apis will only provide block version and so we will get the result in async order. Sometimes we may want to get the result immediately by scarifying the benefit of GCD.

In old style, we can't do it using NSCondition:

__block NSCondition *condition = [[NSCondition alloc] init];
__block ALAssetsGroup *ret = nil;
ALAssetsLibraryGroupsEnumerationResultsBlock listGroupBlock = ^(ALAssetsGroup *group, BOOL *stop) {
[condition lock];
ret = group;
[condition signal];
[condition unlock];
};
ALAssetsLibraryAccessFailureBlock failureBlock = ^(NSError *error) {
[condition lock];
ret = nil;
[condition signal];
[condition unlock];
};
NSUInteger groupTypes = ALAssetsGroupSavedPhotos;
[self.assetsLibrary enumerateGroupsWithTypes:groupTypes usingBlock:listGroupBlock failureBlock:failureBlock];
[condition lock];
[condition wait];
[condition unlock];
return ret;

that we wait for a signal at the end of the block.

For cleaner code, now we can use dispatch_semaphore_t:

dispatch_semaphore_t sema = dispatch_semaphore_create(0);
__block ALAssetsGroup *ret = nil;
ALAssetsLibraryGroupsEnumerationResultsBlock listGroupBlock = ^(ALAssetsGroup *group, BOOL *stop) {
ret = group;
dispatch_semaphore_signal(sema);
};
ALAssetsLibraryAccessFailureBlock failureBlock = ^(NSError *error) {
ret = nil;
dispatch_semaphore_signal(sema);
};
NSUInteger groupTypes = ALAssetsGroupSavedPhotos;
[self.assetsLibrary enumerateGroupsWithTypes:groupTypes usingBlock:listGroupBlock failureBlock:failureBlock];
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
return ret;