除非您在问题描述中留下了一些东西,否则这非常适合 GCD/块组合。事实上,我什至不会使用 NSTimer (GCD 提供了更好的选择 - 参见 dispatch_source_create 例如创建基于 GCD 的计时器),但这是你的电话,而不是问题所问的。无论如何,用GCD...
- (void)handleTimer:(NSTimer *)timer {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
__block id someObject;
// Do work... manipulate someObject in some manner...
// When done, invoke other thread... main thread in this case
dispatch_async(dispatch_get_main_queue(), ^{
// This code is running in a different thread, and can use someObject directly
});
});
}