Skip to content

Commit a2371f1

Browse files
committed
Merge branch 'stephencelis-patch-1'
2 parents 8361639 + 9eb7ff2 commit a2371f1

File tree

2 files changed

+82
-9
lines changed

2 files changed

+82
-9
lines changed

README.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# SwiftyTimer
2+
3+
SwiftyTimer is a set of extensions to make the `NSTimer` API cleaner, nicer to use, and at home with Swift's syntax.
4+
5+
Read [Swifty APIs: NSTimer](http://radex.io/swift/nstimer/) for more information about this project.
6+
7+
### Scheduling a timer
8+
9+
You can easily schedule repeating and non-repeating timers (repeats and delays) using `NSTimer.every` and `NSTimer.after`:
10+
11+
```swift
12+
NSTimer.every(0.7.seconds) {
13+
statusItem.blink()
14+
}
15+
16+
NSTimer.after(1.minute) {
17+
println("Are you still here?")
18+
}
19+
```
20+
21+
SwiftyTimer uses closures instead of target/selector/userInfo.
22+
23+
You can specify time intervals with intuitive [Ruby on Rails](http://rubyonrails.org)-like helpers:
24+
25+
```swift
26+
1.second
27+
2.5.seconds
28+
5.seconds
29+
10.minutes
30+
1.hour
31+
```
32+
33+
You can pass method references instead of closures:
34+
35+
```swift
36+
NSTimer.every(30.seconds, align)
37+
```
38+
39+
If you want to make a timer object without scheduling, use `new(after:)` and `new(every:)`:
40+
41+
```swift
42+
let timer = NSTimer.new(every: 1.second) {
43+
println(self.status)
44+
}
45+
```
46+
47+
(This should be defined as an initializer, but [a bug in Swift](http://www.openradar.me/18720947) prevents this)
48+
49+
### Installation
50+
51+
The simplest way to install this library is to copy `Src/SwiftyTimer.swift` to your project. There's no step two!
52+
53+
#### CocoaPods
54+
55+
You can also install this library using CocoaPods. Just add this line to your Podfile:
56+
57+
```ruby
58+
pod 'SwiftyTimer'
59+
```
60+
61+
Then import library module like so:
62+
63+
```swift
64+
import SwiftyTimer
65+
```
66+
67+
Note that this requires CocoaPods 0.36+, as well as iOS 8 or OS X 10.9+
68+
69+
### Contributing
70+
71+
If you have comments, complaints or ideas for improvements, feel free to open an issue or a pull request.
72+
73+
### Author and license
74+
75+
Radek Pietruszewski
76+
77+
* [github.com/radex](http://github.com/radex)
78+
* [twitter.com/radexp](http://twitter.com/radexp)
79+
* [radex.io](http://radex.io)
80+
* this.is@radex.io
81+
82+
SwiftyTimer is available under the MIT license. See the LICENSE file for more info.

Src/SwiftyTimer.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,6 @@ extension NSTimer {
7676
}
7777
}
7878

79-
extension Int {
80-
public var second: NSTimeInterval { return NSTimeInterval(self) }
81-
public var seconds: NSTimeInterval { return NSTimeInterval(self) }
82-
public var minute: NSTimeInterval { return NSTimeInterval(self * 60) }
83-
public var minutes: NSTimeInterval { return NSTimeInterval(self * 60) }
84-
public var hour: NSTimeInterval { return NSTimeInterval(self * 3600) }
85-
public var hours: NSTimeInterval { return NSTimeInterval(self * 3600) }
86-
}
87-
8879
extension Double {
8980
public var second: NSTimeInterval { return self }
9081
public var seconds: NSTimeInterval { return self }

0 commit comments

Comments
 (0)