UIUpdateLink
An object you use to observe, participate in, and affect the UI update process.
Declaration
@MainActor class UIUpdateLinkOverview
With a UI update link, you can follow the progress of each UI update and express preferences about how those updates happen. Use a UI update link when you need precise and predictable control over the UI update process.
There are multiple use cases for UIUpdateLink, including:
To monitor when UI updates occur and synchronize your drawing code with each update, similar to how you might use CADisplayLink.
To influence how UI updates occur by expressing preferences to the system, such as requesting continuous UI updates, immediate rendering of frames, and more.
To specify precisely at which point in the UI update process to perform certain actions.
To implement support for low-latency input, such as a custom low-latency drawing implementation for a pencil-drawing app.
To create a UI update link, you associate it with a window or a view. The UI update link activates automatically when you add the view to a visible window, and deactivates when you remove the view from it. If the view moves from one display to another, UIUpdateLink adjusts to the timing of the new display automatically.
// Monitor UI updates for a specific view.
let updateLink = UIUpdateLink(view: view)
updateLink.isEnabled = true
// Influence the UI update process by requesting continuous UI updates.
updateLink.requiresContinuousUpdates = true
// Specify one or more actions to perform for each UI update.
// Add an action to the `.beforeCADisplayLinkDispatch` phase, by default.
updateLink.addAction() { link, info in
// Code that runs each UI update, after processing input events,
// but before `CADisplayLink` callbacks.
self.view.center.y = sin(info.modelTime) * 100 + self.view.bounds.midY
}
// Add an action to a specific UI update phase that you choose.
updateLink.addAction(to: .afterUpdateScheduled) { link, info in
// Code that runs each UI update, after the system schedules the update,
// but before processing input events.
// ...
}Topics
Creating a UI update link
init(view:)init(view:actionHandler:)init(view:actionTarget:selector:)init(windowScene:)init(windowScene:actionHandler:)init(windowScene:actionTarget:selector:)
Participating in UI updates
Configuring preferences
requiresContinuousUpdateswantsLowLatencyEventDispatchwantsImmediatePresentationpreferredFrameRateRange