iOS Platform & SwiftUI (50 Qs)•Part 1: SwiftUI Architecture, State & App Lifecycle (1 - 10)
What is the `@Observable` macro in iOS 17+ (Observation Framework)?
senior LevelCode ExampleRxJSLifecycleSystem Design
In Simple Words:
Replaces the legacy ObservableObject and @Published property wrappers:
- Just annotate your class with
@Observable. - SwiftUI automatically tracks property access down to the specific field level: if a view only reads
user.name, changes touser.agewill NOT trigger a view re-render! - Eliminates
@StateObjectand@ObservedObjectboilerplate entirely.
swift
@Observable
class UserProfile {
var name = "Alex"
var score = 100
}