warning: Creating default object from empty value in /var/www/www.waterworld.com.hk/modules/taxonomy/taxonomy.pages.inc on line 33.

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];

Set priority in custom queue of GCD

In iOS GCD, you can use GCD queue to serialize operation by using DISPATCH_QUEUE_SERIAL parameters:

queue = dispatch_queue_create("hk.com.waterworld.previewRenderQueue", DISPATCH_QUEUE_SERIAL);

then you can create a queue dispatch like:

dispatch_async(self.renderQueue, ^{
... your code here ...

but the priority of the queue is unknown, so sometimes, when you queue a lot of task to this queue. It still block the foreground task and make the user interface not smooth.

If fix it, we can:

dispatch_async(self.renderQueue, ^{

Syndicate content