我想将不同的块传递给一个方法。该方法随后将使用传入的块作为 dispatch_async 的参数。
我的块声明如下:
typedef int (^ComputationBlock)(int);
接受块的类方法实现为:
- (void)doSomething:(int)limit withBlock:(ComputationBlock)block;
{
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
// typical in-lined block for dispatch_async:
dispatch_async(queue, ^{
// do some work here
});
// I want to pass in the block as the 2nd parameter to dispatch_async
// but the compiler will warn me of a type mismatch unless I cast
// the block like:
dispatch_async(queue, (dispatch_block_t)block);
}
@end
block
可以将 ' ' 参数类型转换为dispatch_block_t
吗?