In SwiftUI, how do symbolEffect(_:options:value:) and symbolEffect(_:options:isActive:) differ, and how do you animate a favourite heart filling in?
answer
- once per change or while true
- discrete versus indefinite effects
- replace is a content transition
- iOS 17 base, iOS 18 additions
- effects reach images in the subtree
basics
~10 ssymbolEffect(:options:value:) plays a discrete effect such as bounce once each time an Equatable value changes; symbolEffect(:options:isActive:) runs an indefinite effect such as pulse while a Boolean is true. A heart filling in uses contentTransition(.symbolEffect(.replace)).
solid answer
~40 sBoth modifiers arrived in iOS 17 and apply to the symbol images inside the view they modify. The `value:` form takes a `DiscreteSymbolEffect` such as `.bounce` or `.pulse` and plays it once each time the value changes: a cart icon bouncing when an item is added. The `isActive:` form takes an `IndefiniteSymbolEffect` such as `.pulse`, `.variableColor` or `.scale` and runs it while the flag is true: a flame pulsing while a timer runs. The compiler enforces the split. Swapping `heart` for `heart.fill` is neither: you apply `.contentTransition(.symbolEffect(.replace))` and change the name inside `withAnimation`, because content transitions only take effect in an animated transaction. iOS 18 added `.wiggle`, `.rotate` and `.breathe` and made `.bounce` usable with `isActive:`; iOS 26 added `.drawOn`.
code
swift · 28 linesimport SwiftUI
struct FavouriteButton: View {
@State private var isFavourite = false
var body: some View {
Button {
withAnimation {
isFavourite.toggle()
}
} label: {
Image(systemName: isFavourite ? "heart.fill" : "heart")
.contentTransition(.symbolEffect(.replace))
.symbolEffect(.bounce, value: isFavourite)
.foregroundStyle(.red)
}
.accessibilityLabel(isFavourite ? "Remove from favourites" : "Add to favourites")
}
}
struct TimerBadge: View {
let isCooking: Bool
var body: some View {
Image(systemName: "flame")
.symbolEffect(.pulse, options: .repeating, isActive: isCooking)
}
}go deeper
Recall the two forms: value: plays once per change, isActive: runs while true, and both need iOS 17.
Explain discrete, indefinite and content-transition effects, why replace needs withAnimation, and how the compiler enforces which effect fits which modifier.
Show availability gating for iOS 18 and iOS 26 effects, scoping with symbolEffectsRemoved(), and effects tied to meaningful state.
Set a motion guideline for icons with design: which events earn an effect, which effects are allowed, and how they behave on older releases.
## What a symbol effect is SF Symbols can animate in ways a plain image cannot: bounce, pulse, cycle through variable layers, or swap one glyph for another. SwiftUI exposes these through **symbol effects**, available since iOS 17. The effect types themselves (`BounceSymbolEffect`, `PulseSymbolEffect` and the rest) come from Apple's Symbols framework; SwiftUI provides the modifiers that attach them to views. Apple's documentation says an added effect applies to the `Image` views contained by the modified view, and that effects added by ancestors are preserved but may be overridden. ## Two modifiers, two kinds of effect | Modifier | Effect protocol | When it plays | Recipe-app example | |---|---|---|---| | `symbolEffect(_:options:value:)` | `DiscreteSymbolEffect` | once each time `value` changes | cart icon bounces when an ingredient is added | | `symbolEffect(_:options:isActive:)` | `IndefiniteSymbolEffect` | continuously while `isActive` is true | flame pulses while a cooking timer runs | | `contentTransition(.symbolEffect(_:))` | `ContentTransitionSymbolEffect` | when the symbol itself changes in an animation | heart becomes heart.fill | The generic constraints make the split a compile-time rule. `.symbolEffect(.replace, value: isFavourite)` fails because the replace effect is not discrete, and `.contentTransition(.symbolEffect(.bounce))` fails because bounce is not a content-transition effect. Some effects conform to more than one protocol. `.pulse` works with both `value:` and `isActive:` on iOS 17. `.bounce` is discrete on iOS 17 and also indefinite from iOS 18. ## Animating the favourite heart Filling a heart is a change of symbol name, from `heart` to `heart.fill`. The steps are: 1. Choose the name from state: `Image(systemName: isFavourite ? "heart.fill" : "heart")`. 2. Apply `.contentTransition(.symbolEffect(.replace))` so the change is drawn as a symbol replacement rather than a cross-fade. 3. Toggle the state inside `withAnimation`. Apple's `ContentTransition` documentation says content transitions only take effect within transactions that apply an animation. 4. Optionally add `.symbolEffect(.bounce, value: isFavourite)` so the heart also bounces on each tap. ## Options and scoping - `SymbolEffectOptions` tunes playback: `.repeat(2)` plays twice, `.repeating` and `.nonRepeating` control looping, and `.speed(2)` doubles the speed. - Because the modifier reaches every symbol image below it, `.symbolEffect(.pulse)` on a `VStack` pulses all of its symbols; `symbolEffectsRemoved()` on one child opts it out. - `.transition(.symbolEffect(.appear))` animates a symbol as its view is inserted or removed; that belongs with view transitions rather than with these modifiers. - Effects affect symbol images only. A bitmap asset inside the subtree does not bounce. ## Release lines that matter Compiling against the iOS 27 SDK with an iOS 17 deployment target shows the availability lines directly: - iOS 17: `symbolEffect` modifiers, `.bounce` (discrete), `.pulse`, `.variableColor`, `.scale`, `.appear`, `.disappear` and `.replace`. - iOS 18: `.wiggle`, `.rotate` and `.breathe`, and `.bounce` as an indefinite effect. With an iOS 17 target the first three are availability errors; the indefinite bounce is a warning in the Swift 5 language mode and an error in Swift 6 mode. - iOS 26: `.drawOn`, which draws a symbol's strokes in. Wrap newer effects in `if #available(iOS 18, *)` and keep an iOS 17 effect as the fallback. ## Effects versus animations Symbol effects and SwiftUI animations are easy to confuse, and they trigger differently: - A **`value:` effect** starts itself when the value changes; it does not need `withAnimation`, and it plays even though the symbol's name and size stay the same. - An **`isActive:` effect** is driven by the flag alone and keeps running until the flag turns false. - A **replace content transition** is different: it only describes *how* a change of glyph is drawn, so it needs the change to happen inside an animated transaction. - `animation(_:value:)` with a spring animates properties that change, such as a frame or an opacity. It cannot bounce a symbol whose properties did not change. So when an interviewer asks why a heart did not animate, the first question is which of these mechanisms the code relies on. ## Using effects with restraint Effects draw attention, so tie them to a meaningful event: a confirmation, a state that is in progress, or a change the user caused. An indefinite effect left running on many icons is noise, and an effect on every tap of a button the user presses often becomes irritating. Icon-only buttons still need an accessibility label, whatever animates inside them.
- Why does changing the heart's symbol name without withAnimation show no replace effect?A content transition only takes effect in a transaction that carries an animation, as Apple's `ContentTransition` documentation states. Without `withAnimation` or an `animation(_:value:)` covering the change, SwiftUI swaps the glyph instantly. Wrap the state change in `withAnimation`.
- How do you use .wiggle in an app that still supports iOS 17?`.wiggle` is available from iOS 18, so an iOS 17 target fails to compile with it. Put the iOS 18 call behind `if #available(iOS 18, *)` and fall back to `.bounce` with the same `value:` on iOS 17, often through a small view modifier so call sites stay clean.
- symbolEffect(.replace, value:) is how you swap heart for heart.fill.
- An indefinite effect with isActive: plays once per change of the flag.
- Symbol effects animate bitmap assets as well as SF Symbols.
- A replace content transition plays even when the state changes without an animation.
- Wiggle and breathe are available on iOS 17.
Compiled against the iOS 27 SDK: symbolEffect and replace need iOS 17; wiggle, rotate, breathe and an indefinite bounce need iOS 18; drawOn needs iOS 26.