答案: 在哪条线程调用就在哪条线程中执行
@property (nonatomic, copy) void(^block)(NSString *name);
self.block = ^(NSString *name) {
NSLog(@"%@%@",name,[NSThread currentThread]);
};
self.block(@"1");
dispatch_async(dispatch_get_global_queue(0, 0), ^{
NSLog(@"当前在%@",[NSThread currentThread]);
self.block(@"2");
});
输入 :
2017-04-13 14:42:00.954 LZX[1562:106772] 1<NSThread: 0x608000062040>{number = 1, name = main}
2017-04-13 14:42:00.954 LZX[1562:106811] 当前在<NSThread: 0x60800006dac0>{number = 3, name = (null)}
2017-04-13 14:42:00.955 LZX[1562:106811] 2<NSThread: 0x60800006dac0>{number = 3, name = (null)}
网友评论