NSTimer extension which breaks the retain cycle in Swift.

September 28, 2015 ยท View on GitHub

private class Block { let f : T init (_ f: T) { self.f = f } }

extension NSTimer { static func xxx_scheduledTimerWithTimeInterval(ti: NSTimeInterval, block: ()->(), repeats: Bool) -> NSTimer { return self.scheduledTimerWithTimeInterval(ti, target: self, selector: "xxx_blcokInvoke:", userInfo: Block(block), repeats: repeats) }

static func xxx_blcokInvoke(timer: NSTimer) {
    if let block = timer.userInfo as? Block<()->()> {
        block.f()
    }
}

}