Bird
0
0

What is the main purpose of marking a property with @Published in SwiftUI?

easy📝 Conceptual Q11 of 15
iOS Swift - State Management in SwiftUI
What is the main purpose of marking a property with @Published in SwiftUI?
ATo make the property constant
BTo make the property private
CTo automatically notify views when the property changes
DTo prevent the property from being saved
Step-by-Step Solution
Solution:
  1. Step 1: Understand @Published role

    @Published marks a property to send updates when its value changes.
  2. Step 2: Connect to UI updates

    This automatic notification helps SwiftUI views update when data changes.
  3. Final Answer:

    To automatically notify views when the property changes -> Option C
  4. Quick Check:

    @Published = automatic update notification [OK]
Quick Trick: Remember: @Published means auto-update UI on change [OK]
Common Mistakes:
  • Thinking @Published makes property private
  • Confusing @Published with constant declaration
  • Assuming @Published saves data permanently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes