Is it safe to schedule and invalidate NSTimers on a GCD serial queue?

前端 未结 1 1929
误落风尘
误落风尘 2021-02-08 16:18

What\'s the right way to do this? The NSTimer documentation says this:

Special Considerations

You must send this

1条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-08 16:29

    You should not install an NSTimer on an anonymous worker thread managed by GCD.

    Use dispatch timer sources with GCD instead of NSTimer, c.f. dispatch_source_create(3).

    NSTimer relies on the current thread's runloop, which is not something that makes sense for a GCD queue. See the WWDC2012 GCD session for more details around GCD and runloop APIs.

    0 讨论(0)
提交回复
热议问题