Bird
0
0

What happens if you use @ObservedObject on a class that does NOT conform to ObservableObject?

medium📝 Predict Output Q5 of 15
iOS Swift - State Management in SwiftUI
What happens if you use @ObservedObject on a class that does NOT conform to ObservableObject?
AThe view updates normally when properties change.
BThe code fails to compile with an error.
CThe app crashes at runtime.
DThe code compiles but the view never updates on changes.
Step-by-Step Solution
Solution:
  1. Step 1: Check protocol conformance requirement

    @ObservedObject requires the class to conform to ObservableObject to notify changes.
  2. Step 2: Understand behavior without conformance

    Without ObservableObject, no change notifications occur, so view won't update.
  3. Final Answer:

    The code compiles but the view never updates on changes. -> Option D
  4. Quick Check:

    Missing ObservableObject = no view updates [OK]
Quick Trick: ObservableObject conformance needed for updates [OK]
Common Mistakes:
  • Expecting compile error without conformance
  • Assuming view updates anyway
  • Confusing runtime crash with silent failure

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes