block在主线程还是在分线程中执行

答案: 在哪条线程调用就在哪条线程中执行

@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{number = 1, name = main}
2017-04-13 14:42:00.954 LZX[1562:106811] 当前在{number = 3, name = (null)}
2017-04-13 14:42:00.955 LZX[1562:106811] 2{number = 3, name = (null)}

你可能感兴趣的:(block在主线程还是在分线程中执行)