Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rudifa/faveflicks
Learning SwiftUI data flow - based on a RW tutorial
https://github.com/rudifa/faveflicks
Last synced: 24 days ago
JSON representation
Learning SwiftUI data flow - based on a RW tutorial
- Host: GitHub
- URL: https://github.com/rudifa/faveflicks
- Owner: rudifa
- Created: 2021-10-29T18:33:04.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2021-10-29T18:34:25.000Z (about 3 years ago)
- Last Synced: 2024-10-06T01:41:24.655Z (about 1 month ago)
- Language: Swift
- Homepage:
- Size: 429 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Understanding Data Flow in SwiftUI
A [RW tutorial](https://www.raywenderlich.com/11781349-understanding-data-flow-in-swiftui)
See also [State and Data Flow](https://developer.apple.com/documentation/swiftui/state-and-data-flow)
## Property Wrappers in SwiftUI
```
@State
@Binding
@StateObject
@ObservedObject
@EnvironmentObject
@Environment
```| `wrapper / protocol` | `type` | `note / example` |
|----------------------|-------------|---------------------|
| `@State` | `value` | `local state within a view` |
| `@Binding` | `reference` | `share a reference to a source of truth` |
| `@StateObject` | `reference` | `@StateObject var movieStore = MovieStore()`|
| `ObservableObject` | `protocol` | `object with a publisher that emits before`
` the object has changed`
|
| `@ObservedObject` | `reference` | `class MovieStore: ObservableObject`
|
| `@EnvironmentObject` | `reference` | `class UserStore: ObservableObject,`
`with at least one @Published variable;`
`@EnvironmentObject var userStore: UserStore`
`supplied to an ancestor object,`
` visible by descenants` |
| `@Environment` | | |
| | | |
| `@ Published ` | | `triggers updates in observers `
`of an ObservableObject` || `example` | `comment` | `note`|
|----------------------|---------------------|---------------------|
| `@State private var isVisible = true` | `declare isVisible as a state variable` | |
| `if isVisible { Text("Hello") }` | `render only when isVisible is true` | `wrapped value`|
| `Toggle("Visible", isOn: $isVisible)` | `update the wrapped value` |`projected value`|
| | |
| | |
| | |### Which wrapper?
![alt](./FaveFlicks/App/Assets.xcassets/SwiftUI-property-wrappers.imageset/SwiftUI-property-wrappers.png)