Skip to content

Commit 30fb085

Browse files
committed
Resume and cancel timer in deinit only if timer is not nil
1 parent 6a3fc92 commit 30fb085

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

Sources/Instruments/Timer/Timer.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public class Timer {
3838

3939
private var state: State = .notRunning
4040

41+
// MARK: -
42+
4143
private let interval: TimeInterval
4244
private let repeats: Bool
4345
private let queue: DispatchQueue?
@@ -69,6 +71,10 @@ public class Timer {
6971
}
7072

7173
deinit {
74+
if timer == nil {
75+
return
76+
}
77+
7278
// If the timer is suspended, calling cancel without resuming triggers a crash. This is
7379
// documented here https://forums.developer.apple.com/thread/15902
7480
timer?.setEventHandler { }

0 commit comments

Comments
 (0)