Bird
0
0

Identify the error in this Swift animation code: UIView.animate(withDuration: 0.5) { myView.alpha = 0.5 completion: { print("Done") } }

medium📝 Debug Q6 of 15
iOS Swift - Animations
Identify the error in this Swift animation code: UIView.animate(withDuration: 0.5) { myView.alpha = 0.5 completion: { print("Done") } }
AThe duration must be a string
BThe completion block is incorrectly placed inside the animation closure
CThe alpha value must be an integer
DUIView.animate does not support alpha animations
Step-by-Step Solution
Solution:
  1. Step 1: Review UIView.animate syntax

    The completion block is a separate parameter, not inside the animation closure.
  2. Step 2: Identify the error

    Placing completion inside the closure causes a syntax error.
  3. Final Answer:

    The completion block is incorrectly placed inside the animation closure -> Option B
  4. Quick Check:

    Completion block placement matters = C [OK]
Quick Trick: Place completion outside animation closure [OK]
Common Mistakes:
  • Putting completion inside closure
  • Using wrong alpha type
  • Misusing duration parameter

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes