Skip to content

Commit 4de0130

Browse files
committed
Document invalidation in repeating timers in Readme
1 parent b5009e9 commit 4de0130

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,20 @@ timer.start()
6262
timer.start(modes: NSDefaultRunLoopMode, NSEventTrackingRunLoopMode)
6363
```
6464

65+
### Invalidation
66+
67+
If you want to invalidate a repeating timer on some condition, you can take an `NSTimer` argument in the closure you pass in:
68+
69+
```swift
70+
NSTimer.every(5.seconds) { (timer: NSTimer) in
71+
// do something
72+
73+
if finished {
74+
timer.invalidate()
75+
}
76+
}
77+
```
78+
6579
## Installation
6680

6781
If you're using CocoaPods, just add this line to your Podfile:

0 commit comments

Comments
 (0)