1. Properties: data that isn't mutated by the view.
2. `@State`: Source of truth. For transient data owned by the view
3. `@Binding`: For mutating data owned by another view. State에서만 binding을 만들 수 있는 것이 아니라 Binding에서도 만들 수 있다. ObservableObject에서도 Binding을 만들 수 있다 (Observable Object 내의 value type인 변수라면 가능).
예)
struct EditorConfig {
var note = ""
}
struct ProgressEditor: View {
@Binding var editorConfig: EditorConfig
TextEditor($editorConfig.note)
}
// editorConfig binding으로부터 editorConfig.note라는 새로운 binding을 만들 수 있다.
ObservableObject
- For reference type
- Source of Truth
- Manager life cycle of your data
- Handle side-effects
- Integrate with existing components
`@Published`
- Automatically works with `ObservableObject`
- Publishes every time the value changes in `willSet`
- ptojectedValue is a Publisher
`ObservableObject as the data dependency surface` 가 무엇을 의미하는 지 예시?
ObservableObject Dependency
: ObservableObject as the data dependency surface.
1. ObservedObject
- ObservedObject를 사용할 때, SwiftUI는 objectWillChange를 subscribe해서 ObservableObject가 willChange할 때 마다 all the view that depends on it will be changed.
- did change가 아닌 will change인 이유? 바뀌려고 하는 것들의 정보를 모두 합쳐서 한번에 업데이트 하기 위해 willChange를 이용한다.
- It creates a data dependency.eee
2. StateObject
- 해당 객체는 body가 작동하기 직전에 instantiated.
- View가 더 이상 필요 없어지면 자동으로 release된다.
- It ties an ObservableObject to a view's life cycle.
3. EnvironmentObject
아래와 같은 경우에 사용 가능

- It adds ergonomics to access ObservableObject!

@StateObject를 @ObservedObject 대신 사용하면,
불필요한 heap allocation을 방지하고 data loss를 방지한다.
## Source of Truth lifetime
Process Lifetime
1. State
2. StateObject
3. Constnat
Extended Lifetime: 값들이 User defaults에 저장되어 사용됨
4. SceneStorage: Scene-scoped
5. AppStorage: App-scoped
Custom Lifetime
6. ObservableObject
https://developer.apple.com/videos/play/wwdc2020/10040/
Data Essentials in SwiftUI - WWDC20 - Videos - Apple Developer
Data is a complex part of any app, but SwiftUI makes it easy to ensure a smooth, data-driven experience from prototyping to production...
developer.apple.com