我希望能够执行block
在下一次运行循环迭代中。它是在下一个运行循环的开始还是结束时执行并不那么重要,只是执行会推迟到当前运行循环中的所有代码都完成执行为止。
我知道以下内容不起作用,因为它与主运行循环交错,因此我的代码可能会在下一个运行循环上执行,但也可能不会。
dispatch_async(dispatch_get_main_queue(),^{
//my code
});
我相信以下内容也遇到了与上面相同的问题:
dispatch_after(DISPATCH_TIME_NOW, dispatch_get_main_queue(), ^(void){
//my code
});
Now I believe以下内容将起作用,因为它被放置在当前运行循环的末尾(如果我错了,请纠正我),这实际上会起作用吗?
[self performSelector:@selector(myMethod) withObject:nil afterDelay:0];
带有一个定时器怎么样?0
间隔?文档指出:If seconds is less than or equal to 0.0, this method chooses the nonnegative value of 0.1 milliseconds instead.
这是否意味着保证下一次运行循环迭代的执行?
[NSTimer scheduledTimerWithTimeInterval:0 target:self selector:@selector(myMethod) userInfo:nil repeats:NO];
这就是我能想到的所有选项,但我仍然距离在下一次运行循环迭代中执行块(而不是调用方法)更近,并保证它不会更快。