How do you schedule a block to run on the next run loop iteration?

后端 未结 5 2340
隐瞒了意图╮
隐瞒了意图╮ 2020-12-02 04:36

I want to be able to execute a block on the next run loop iteration. It\'s not so important whether it gets executed at the beginning or the end of the next run

5条回答
  •  再見小時候
    2020-12-02 05:24

    dispatch_async on mainQueue is a good suggestion but it does not run on the next run loop it is inserted into the current run in the loop.

    To get the behavior you are after you will need to resort to the traditional way:

    [self performSelector:@selector(myMethod) withObject:nil afterDelay:0];
    

    This also gives the added advantage is it can be canceled using NSObject's cancelPreviousPerforms.

提交回复
热议问题