JoanKing / JKSwiftExtension

Swift常用扩展、组件、协议,方便项目快速搭建,提供完整清晰的Demo示例,不断的完善中......
Apache License 2.0
761 stars 122 forks source link

timer #18

Closed plkgq closed 2 years ago

plkgq commented 2 years ago
image

创建一个定时的timer timer = JKWeakTimer(timeInterval: 0.1, target: self, selector: #selector(), userInfo: nil, repeats: true) deinit时会崩溃

plkgq commented 2 years ago

Thread 1: EXC_BREAKPOINT

plkgq commented 2 years ago

具体来说,当创建一个定时的timer = JKWeakTimer(timeInterval: 10, target: self, selector: #selector(), userInfo: nil, repeats: true) 如果此时time还没有启动执行fire函数,这时退出当前controller,执行deinit函数就会崩溃, 若执行过fire,不会崩溃

JoanKing commented 2 years ago

在JKWeakTimer销毁的方法里面修复了,具体的您看 invalidate() 方法,具体如下 dispatch_suspend 状态下直接释放定时器,会导致定时器崩溃。初始状态,挂起状态,都不能直接调用 dispatch_source_cancel(timer);调用就会导致app闪退,先调用下 dispatch_resume后再cancel,然后再释放timer