How do I opt into ProMotion and variable refresh rate in Swift?

To enable ProMotion and variable refresh rate in your Swift application, you need to set your display's preferred frame rate and configure the view that you want to use with a variable refresh rate. ProMotion allows for smoother animations and more responsive interactions by dynamically adjusting the refresh rate based on the content being displayed.

Here’s a basic example of how to opt into ProMotion in a UIViewController:

override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) if #available(iOS 15.0, *) { let displayLink = CADisplayLink(target: self, selector: #selector(update)) displayLink.preferredFramesPerSecond = 120 // Set the preferred frame rate to 120Hz displayLink.add(to: .current, forMode: .default) } } @objc func update() { // Update your UI here }

ProMotion variable refresh rate iOS development Swift