Bird
0
0

Examine this SwiftUI code snippet:

medium📝 Debug Q7 of 15
iOS Swift - Animations
Examine this SwiftUI code snippet:
@Namespace var ns

var body: some View {
  VStack {
    Text("First")
      .matchedGeometryEffect(id: "label", in: ns)
    Text("Second")
      .matchedGeometryEffect(id: "label", in: ns)
  }
}
What is the issue with this usage of matchedGeometryEffect?
AThe namespace variable is not declared properly.
BBoth views use the same id and namespace simultaneously, causing conflict.
CmatchedGeometryEffect requires unique ids for each view within the same namespace.
DmatchedGeometryEffect cannot be applied to Text views.
Step-by-Step Solution
Solution:
  1. Step 1: Identify id usage

    Both Text views use the same id "label" with the same namespace.
  2. Step 2: Understand matchedGeometryEffect constraints

    matchedGeometryEffect expects the id to be unique per view pair to animate between them, not simultaneously on multiple views.
  3. Step 3: Recognize conflict

    Applying the same id to multiple views at the same time causes ambiguity and prevents animation.
  4. Final Answer:

    Both views use the same id and namespace simultaneously, causing conflict. -> Option B
  5. Quick Check:

    Same id on multiple views at once causes conflict [OK]
Quick Trick: Same id on multiple views simultaneously causes conflict [OK]
Common Mistakes:
  • Assuming multiple views can share the same id at the same time
  • Misunderstanding namespace declaration
  • Thinking matchedGeometryEffect is limited to certain view types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes