Bird
0
0

Why does marking a property with @Published inside an ObservableObject cause SwiftUI views to update automatically?

hard📝 Conceptual Q10 of 15
iOS Swift - State Management in SwiftUI
Why does marking a property with @Published inside an ObservableObject cause SwiftUI views to update automatically?
ABecause @Published disables property caching.
BBecause @Published stores the property in a special memory area.
CBecause @Published creates a publisher that emits events on value changes, triggering view updates.
DBecause @Published forces the property to be immutable.
Step-by-Step Solution
Solution:
  1. Step 1: Understand @Published internals

    @Published wraps the property with a publisher that emits events when the value changes.
  2. Step 2: Connect publisher to SwiftUI views

    SwiftUI subscribes to these events and refreshes views automatically on changes.
  3. Final Answer:

    Because @Published creates a publisher that emits events on value changes, triggering view updates. -> Option C
  4. Quick Check:

    @Published creates publisher for view updates = A [OK]
Quick Trick: @Published creates a publisher that triggers UI refresh [OK]
Common Mistakes:
  • Thinking @Published changes memory storage
  • Believing @Published disables caching
  • Assuming @Published makes property immutable

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes