在下面的代码中,我试图将类型为dispatch_block_t的块传递给dispatch_async,如下所示。我尝试了以下]]
dispatch_async(defaultPriority, block1(2, 3000)); dispatch_async(defaultPriority, (^block1)(2, 3000)); dispatch_async(defaultPriority, ^(block1)(2, 3000));
但是,由于将块传递给dispatch_asynch方法的方式导致生成的错误,因此代码不可编译。请让我知道如何解决它。它。如果可以的话,您可以提供不同的方式来传递它,那就太好了。
main
dispatch_block_t ^block1(int, int) = ^(int x1, int delay) {
[NSThread sleepForTimeInterval: delay];
};
dispatch_queue_t defaultPriority = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_queue_t backgroundPriority = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0);
dispatch_async(defaultPriority, block1(2, 3000));
synchName andId: (NSString *) synchId;
@end
在下面的代码中,我试图将类型为dispatch_block_t的块传递给dispatch_async,如下所示。我尝试了以下dispatch_async(defaultPriority,block1(2,3000)); ...
dispatch_block_t
被定义为不带参数的闭包: