2
非常簡單的代碼:爲什麼在主線程上運行?
queue = [[NSOperationQueue alloc] init];
[queue addOperationWithBlock:^{
NSLog(@"%@", [NSThread mainThread]? @"main" : @"not main");
}];
版畫 「主」。
爲什麼?是不是假設以異步方式在bg線程中運行,除非我撥打[NSOperationQueue mainQueue]
?
Ahhhh ...狗屎。我認爲它返回BOOL指示是否你正在從主線程調用或不。謝謝。 – 0xSina
您只需要[[NSThread isMainThread]]。 – borrrden
@borrrden哎呀..我怎麼會錯過?如果我將它添加到答案中,你介意嗎? – Krishnabhadra