Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eonist/54e86d41dba857123f3a to your computer and use it in GitHub Desktop.
Save eonist/54e86d41dba857123f3a to your computer and use it in GitHub Desktop.
CVDisplayLinkOutputCallback in Swift
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