Bird
0
0

Identify the error in this SwiftUI code snippet:

medium📝 Debug Q6 of 15
iOS Swift - Animations
Identify the error in this SwiftUI code snippet:
Text("Hello")
  .animation(.easeInOut, value: isVisible)
  .onTapGesture { isVisible.toggle() }
AonTapGesture cannot toggle state
BIncorrect animation type used
CMissing @State declaration for isVisible
DText cannot be animated
Step-by-Step Solution
Solution:
  1. Step 1: Check state variable usage

    The code uses isVisible but does not declare it as @State, which is required for state changes.
  2. Step 2: Verify animation and gesture correctness

    The animation and onTapGesture usage are correct if isVisible is a @State variable.
  3. Final Answer:

    Missing @State declaration for isVisible -> Option C
  4. Quick Check:

    @State needed for variables toggled in UI [OK]
Quick Trick: Declare toggled variables with @State for animations [OK]
Common Mistakes:
  • Forgetting @State
  • Wrong animation type
  • Thinking Text can't animate

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes