DevPrep

All topics › SwiftUI

How do SwiftUI animations work: implicit, explicit, Transaction and transitions?

Middle PRO

The gist

In SwiftUI it is not a view that is animated but a state change. Every update travels with a Transaction — a context that carries an animation (or nil). Once the new tree is built, animatable properties (frame, opacity, color, shapes' animatableData) are interpolated from the old value to the new one using the transaction's animation. It does not matter how the animation got there — explicitly via withAnimation or implicitly via a modifier.

The rest of this answer, with code and interview follow-ups, is in the DevPrep app.

Read the full answer in DevPrep

Practice this before your interview

DevPrep turns these answers into one-minute challenges: what does this code print, find the bug, mock interviews. One challenge a day.

Get DevPrep on the App Store