How to Wait in Objective-C and Swift

后端 未结 8 890
自闭症患者
自闭症患者 2021-01-31 02:22

I want to change my UILabel\'s text after 2 seconds.

I tried setting my UILabel\'s text to \"A text\", and use sleep(2) a

8条回答
  •  灰色年华
    2021-01-31 02:53

    The follow method is good.

    You can replace your

    sleep(1);

    with

    dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); dispatch_semaphore_wait(semaphore, dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC));

提交回复
热议问题