Created
July 31, 2015 14:24
-
-
Save IainDelaney/9f59050b2ac4a97fc7cf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@objc protocol Timer { | |
func scheduleTimer(target:AnyObject, selector: Selector, interval: NSTimeInterval)->String | |
func cancelTimer(id:String) | |
} | |
@objc class NSTimerService: Timer { | |
var timers:[String:NSTimer] = [:] | |
func scheduleTimer(target:AnyObject, selector: Selector, interval: NSTimeInterval)->String { | |
let id = NSUUID().UUIDString | |
timers[id] = NSTimer.scheduledTimerWithTimeInterval(interval, target: target, selector: selector, userInfo: nil, repeats: true) | |
return id | |
} | |
func cancelTimer(id:String) { | |
timers[id]?.invalidate() | |
} | |
deinit { | |
println("Timer service destoryed.") | |
for t in timers.keys { | |
timers[t]?.invalidate() | |
} | |
timers.removeAll(keepCapacity: false) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How many stupids can you find in this code, not including the entire concept?