Forked from eyeplum/CVDisplayLinkOutputCallback.swift
Created
March 10, 2016 19:23
-
-
Save eonist/54e86d41dba857123f3a to your computer and use it in GitHub Desktop.
CVDisplayLinkOutputCallback 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
private func createDisplayLink() { | |
CVDisplayLinkCreateWithActiveCGDisplays(&displayLink) | |
guard let displayLink = displayLink else { | |
return | |
} | |
let callback: CVDisplayLinkOutputCallback = { (_, _, _, _, _, userInfo) -> CVReturn in | |
let myView = Unmanaged<MyView>.fromOpaque(COpaquePointer(userInfo)).takeUnretainedValue() | |
dispatch_async(dispatch_get_main_queue()) { | |
myView.update() | |
} | |
return kCVReturnSuccess | |
} | |
let userInfo = UnsafeMutablePointer<Void>(Unmanaged.passUnretained(self).toOpaque()) | |
CVDisplayLinkSetOutputCallback(displayLink, callback, userInfo) | |
CVDisplayLinkStart(displayLink) | |
} | |
private func update() { | |
// Do your view updates | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment