Why would a `scheduledTimer` fire properly when setup outside a block, but not within a block?

后端 未结 3 1904
醉话见心
醉话见心 2020-12-03 13:29

The following code snippet works perfectly when called outside a completion block, but the timer is never fired when I set it up inside the block. I don\'t understand why th

3条回答
  •  有刺的猬
    2020-12-03 14:27

    This may sound obvious, but I had a similar problem, the timer just wouldn't fire and the reason is that it wasn't in the main thread...No errors, just never fired.

    Put in the main thread and at least you have a shot at it!

     DispatchQueue.main.async {
      //insert your timer here
    }
    

提交回复
热议问题