# SwiftUI Data Flow & Composition

> State, Binding, Observable models and the Environment; view identity; NavigationStack; and composing reusable views. Free notes, key concepts, resources and a...

Canonical: https://www.internhack.in/roadmaps/tracks/mobile/swiftui-in-depth
Last updated: 2026-11-28

State, Binding, Observable models and the Environment; view identity; NavigationStack; and composing reusable views.

Intermediate · about 10 hours · difficulty 3/5

Learn first: [iOS App Lifecycle, Xcode Projects & Capabilities](https://www.internhack.in/roadmaps/tracks/mobile/ios-fundamentals), [App-wide State Tools](https://www.internhack.in/roadmaps/tracks/mobile/state-libraries)

SwiftUI views are lightweight value types recreated often. Data flow tools tell SwiftUI what owns the truth and when to re-render.

### Property wrappers and observation

- `@State`: private, view-owned value state.
- `@Binding`: a two-way reference to state owned by a parent, used for reusable inputs.
- `@Observable` classes (Observation framework): shared model objects; views update when the properties they read change. Own them with `@State` and pass them down or put them in the `@Environment`.
- `@Environment`: read system values (colour scheme, dismiss) or your injected models.

### Identity and lists

`ForEach` and `List` need stable `Identifiable` IDs. Changing a view's identity (for example with `.id()` or conditional branches) resets its state.

### Navigation

`NavigationStack` with `.navigationDestination(for:)` and a path array enables programmatic and deep-link navigation. Sheets use `.sheet(item:)`.

### Composition tips

- Extract subviews early; small views are faster to diff and easier to preview.
- Create custom `ViewModifier`s and styles for consistent design.
- Use `.task` to start async work tied to a view's lifetime; it cancels automatically.

**Good enough to move on:** you can build a list-detail-edit flow where edits propagate through a shared Observable model.

## Key concepts

- **@State and @Binding**
- **@Observable models**
- **Environment injection**
- **View identity and Identifiable**
- **NavigationStack and typed paths**
- **The .task modifier**
- **Custom ViewModifiers and styles**
- **Previews with sample data**

## Mini project

Build a recipe manager with list, detail and edit screens sharing one Observable store, plus programmatic navigation to a newly created recipe.

## Check yourself

When should a child view take a @Binding instead of its own @State?

## Free resources

- [SwiftUI documentation](https://developer.apple.com/documentation/swiftui) (Apple)
- [Managing model data in your app](https://developer.apple.com/documentation/swiftui/managing-model-data-in-your-app) (Apple)
- [SwiftUI tutorials](https://developer.apple.com/tutorials/swiftui) (Apple)

Previous: [iOS App Lifecycle, Xcode Projects & Capabilities](https://www.internhack.in/roadmaps/tracks/mobile/ios-fundamentals) · Next: [Swift Concurrency & Persistence (SwiftData, Core Data)](https://www.internhack.in/roadmaps/tracks/mobile/ios-concurrency-data)

## More in iOS with Swift in Depth

- [iOS App Lifecycle, Xcode Projects & Capabilities](https://www.internhack.in/roadmaps/tracks/mobile/ios-fundamentals)
- [SwiftUI Data Flow & Composition](https://www.internhack.in/roadmaps/tracks/mobile/swiftui-in-depth)
- [Swift Concurrency & Persistence (SwiftData, Core Data)](https://www.internhack.in/roadmaps/tracks/mobile/ios-concurrency-data)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Mobile App Developer Roadmap](https://www.internhack.in/roadmaps/tracks/mobile)
