Swift Academy · Lesson

Implicit vs Explicit Animations

Using .animation() modifier vs withAnimation {} block for different use cases.

Lesson 1 of 413 steps

Implicit vs Explicit Animations is a free Swift Academy lesson on CoddyKit. This is lesson 1 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the Swift Academy learning path, and your progress syncs across the web and the CoddyKit app. The Swift Academy course includes 4 lessons in total.

Two Animation Styles

SwiftUI supports implicit animations (the .animation modifier) and explicit animations (the withAnimation closure).

struct Demo: View {
  @State private var scale = 1.0
  var body: some View {
    Circle().scaleEffect(scale)
  }
}

Implicit Animation with .animation

Attaching .animation(_:value:) to a view animates it whenever the bound value changes.

Circle()
  .scaleEffect(scale)
  .animation(.easeInOut(duration: 0.3), value: scale)

Triggering Implicit Animation

Any state change that affects the view automatically triggers the implicit animation defined on it.

Button("Grow") {
  scale = 2.0  // .animation fires automatically
}

Explicit Animation with withAnimation

withAnimation wraps a state mutation and animates all resulting view changes simultaneously.

Button("Animate") {
  withAnimation(.spring()) {
    scale = 2.0
    offset = 50
  }
}

Animating Multiple Properties

withAnimation is better when you want to animate several state changes in sync as a single transaction.

withAnimation(.easeOut(duration: 0.5)) {
  isExpanded = true
  rotation = 90
  opacity = 0.5
}

Animation Types

Swift provides spring, easeIn, easeOut, easeInOut, linear, and custom timing curve animations.

.spring(response: 0.4, dampingFraction: 0.6)
.easeInOut(duration: 0.3)
.linear(duration: 0.5)
.timingCurve(0.2, 0.8, 0.2, 1.0, duration: 0.4)

Disabling Animation

Pass .animation(.none, value:) or wrap mutations in withAnimation(nil) to disable animation selectively.

Circle()
  .scaleEffect(scale)
  .animation(.none, value: scale)  // no animation

Animation Priority

Explicit withAnimation takes priority over implicit .animation modifiers on child views.

withAnimation(.linear) {
  value = true  // linear wins over any .animation on subviews
}

Repeating Animations

Use .repeatForever or .repeatCount for looping animations like pulsing effects.

.animation(
  .easeInOut(duration: 0.8).repeatForever(autoreverses: true),
  value: pulsing
)

Delay and Speed

Compose animations with .delay and .speed modifiers on the animation value.

.animation(.spring().delay(0.2).speed(1.5), value: flag)

Choosing Implicit vs Explicit

Use implicit for single-view animations tied to one value; use explicit when coordinating multiple properties or views.

// Implicit: simple, single view
.animation(.easeIn, value: isVisible)
// Explicit: multi-property or cross-view
withAnimation { a = 1; b = 2 }

Quick Check

Which approach best coordinates animating multiple state properties simultaneously?

Lesson Recap

Implicit animations (.animation(_:value:)) react automatically to value changes on a single view. Explicit animations (withAnimation {}) coordinate multiple mutations. Compose with .delay, .speed, and .repeatForever for complex effects.

Free to start

Learn Swift with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
122
Lessons
409

Frequently Asked Questions

Is the “Implicit vs Explicit Animations” lesson free?

Yes — any 3 lessons of the Swift Academy learning path, including “Implicit vs Explicit Animations”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The Swift Academy course includes 4 lessons in total.

What will I learn in “Implicit vs Explicit Animations”?

Using .animation() modifier vs withAnimation {} block for different use cases. You practise Swift Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Swift Academy?

No prior experience is required. Swift Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 1 of 4.

How long does the “Implicit vs Explicit Animations” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Swift Academy lesson?

Yes. Every Swift Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Implicit vs Explicit Animations
  2. matchedGeometryEffect for Hero Transitions
  3. Custom AnimatableModifier and Animatable
  4. TimelineView and Canvas for High-Performance Drawing
← Back to Swift Academy