Created
October 4, 2014 08:39
-
-
Save aleclarson/7e61dfce02417714915c to your computer and use it in GitHub Desktop.
DisplayLink.swift
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
import Nucleus | |
let display = DisplayLink() | |
public class DisplayLink { | |
private init () { | |
link = CADisplayLink(target: self, selector: "callClosures") | |
link.addToRunLoop(NSRunLoop.mainRunLoop(), forMode: NSRunLoopCommonModes) | |
} | |
public func link (id: String, _ closure: VoidFunc) { | |
closures[id] = closure | |
} | |
public func unlink (id: String) { | |
closures[id] = nil | |
} | |
private let link: CADisplayLink! | |
private var closures = [String:VoidFunc]() | |
@objc private func callClosures () { | |
for (_, closure) in closures { closure() } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment