Created
October 14, 2015 07:44
-
-
Save billwang1990/5506cd3f8e94043927a9 to your computer and use it in GitHub Desktop.
Non retain cycle NSTimer in Swift
This file contains 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
public typealias TimerExcuteClosure = @convention(block)()->() | |
extension NSTimer{ | |
public class func YQ_scheduledTimerWithTimeInterval(ti:NSTimeInterval, closure:TimerExcuteClosure, repeats yesOrNo: Bool) -> NSTimer{ | |
return self.scheduledTimerWithTimeInterval(ti, target: self, selector: "excuteTimerClosure:", userInfo: unsafeBitCast(closure, AnyObject.self), repeats: true) | |
} | |
class func excuteTimerClosure(timer: NSTimer) | |
{ | |
let closure = unsafeBitCast(timer.userInfo, TimerExcuteClosure.self) | |
closure() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment