How to make thread sleep for seconds in iOS?

后端 未结 5 1978
予麋鹿
予麋鹿 2021-02-04 19:39

In iOS env, is it possible to make current thread sleep for seconds, then execute my code? NSTimer, GDC or any technique is okay for me.

5条回答
  •  说谎
    说谎 (楼主)
    2021-02-04 20:00

    Either

    [self performSelector:@selector(YourFunctionName) withObject:(can be Self or Object from other Classes) afterDelay:(Time Of Delay)];`
    

    or

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), 
        dispatch_get_main_queue(), ^{
        //your method 
    });
    

提交回复
热议问题