How to make thread sleep for seconds in iOS?

后端 未结 5 2084
予麋鹿
予麋鹿 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:11

    it depends how you are creating (spawning) your threads. For example if you are creating your thread with NSThread class, you can use the two class methods :

    sleepUntilDate:
    sleepForTimeInterval:
    

    But generally it's a bad idea to handle the threading management yourself, because multithreading programming is very hard. You can use GCD or operations queues for example to handle the multithreading in your application.

提交回复
热议问题