Bird
0
0

In SwiftUI, what happens when you mark a property with @Published inside an ObservableObject?

easy📝 Conceptual Q1 of 15
iOS Swift - State Management in SwiftUI
In SwiftUI, what happens when you mark a property with @Published inside an ObservableObject?
AIt automatically notifies subscribers when the property's value changes.
BIt makes the property immutable after initialization.
CIt delays the property's initialization until first access.
DIt encrypts the property's value for security.
Step-by-Step Solution
Solution:
  1. Step 1: Understand @Published

    The @Published property wrapper is used to automatically announce changes to a property.
  2. Step 2: Role in ObservableObject

    When a property marked with @Published changes, it notifies any subscribers, such as SwiftUI views observing the object.
  3. Final Answer:

    It automatically notifies subscribers when the property's value changes. -> Option A
  4. Quick Check:

    Does @Published notify changes? Yes [OK]
Quick Trick: Published properties notify changes automatically [OK]
Common Mistakes:
  • Thinking @Published makes properties immutable
  • Confusing @Published with lazy initialization
  • Assuming @Published encrypts data

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes