【发布时间】:2014-11-23 07:36:16
【问题描述】:
在Apple's doc 中,当我想捕获 CoreFoundation 对象时,我找不到我能做什么。
但在 Apple 的 Concurrency Programming Guide 中。当调度对象不支持ARC时,示例代码似乎使用了一些代码,就像这样:
void average_async(int *data, size_t len, dispatch_queue_t queue, void (^block)(int))
{
// Retain the queue provided by the user to make
// sure it does not disappear before the completion
// block can be called.
dispatch_retain(queue);
// Do the work on the default concurrent queue and then
// call the user-provided block with the results.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
int avg = average(data, len);
dispatch_async(queue, ^{ block(avg);});
// Release the user-provided queue when done
dispatch_release(queue);
});
}
我是否需要像之前的DispatchObject 一样使用CFObject。但是如果我需要多次调用该块呢?
也许我可以使用__attribute__((NSObject)),但我不知道会发生什么!
Apple 对此有什么说法吗?
【问题讨论】:
标签: ios objective-c automatic-ref-counting objective-c-blocks core-foundation