<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/initializing-observable-classes-within-the-swiftui-hierarchy-xwf9sc2fk" -->

---
title: Initializing @Observable classes within the SwiftUI...
description: A detailed guide on how to correctly initialize and store @Observable classes within SwiftUI views. Covers why @State is necessary to tie observable models to...
canonical: https://daily.dev/posts/initializing-observable-classes-within-the-swiftui-hierarchy-xwf9sc2fk
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Initializing @Observable classes within the SwiftUI hierarchy | daily.dev
og:description: A detailed guide on how to correctly initialize and store @Observable classes within SwiftUI views. Covers why @State is necessary to tie observable models to...
og:url: https://daily.dev/posts/initializing-observable-classes-within-the-swiftui-hierarchy-xwf9sc2fk
og:image: https://api.daily.dev/og/posts/XWF9Sc2fk.png
og:image:alt: Initializing @Observable classes within the SwiftUI hierarchy
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Initializing @Observable classes within the SwiftUI hierarchy

**[Nil Coalescing](https://daily.dev/sources/nilcoalescing)** · 8 min read · 0 upvotes · 0 comments

## Summary

A detailed guide on how to correctly initialize and store @Observable classes within SwiftUI views. Covers why @State is necessary to tie observable models to the view lifecycle, the problem of models being recreated on every view rebuild, how to defer initialization using task() modifiers, how to reinitialize models when input changes using task(id:), and how to share observable state across multiple scenes via the App struct and environment. Also notes that Xcode 27 fixes the redundant initializer evaluation issue with a lazy @State macro.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://nilcoalescing.com/blog/InitializingObservableClassesWithinTheSwiftUIHierarchy>

## Similar posts on daily.dev

- [Who Told The View To Update?](https://daily.dev/posts/who-told-the-view-to-update--xvxtydysb) · Medium · 0 upvotes · 0 comments
- [SwiftUI data dependencies and their effect on view updates](https://daily.dev/posts/swiftui-data-dependencies-and-their-effect-on-view-updates-2kp42i6if) · Nil Coalescing · 1 upvotes · 0 comments

---

Tags: [#ios](https://daily.dev/tags/ios), [#swift](https://daily.dev/tags/swift), [#swiftui](https://daily.dev/tags/swiftui)

[View this post on daily.dev](https://daily.dev/posts/initializing-observable-classes-within-the-swiftui-hierarchy-xwf9sc2fk)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Initializing @Observable classes within the SwiftUI hierarchy","url":"https://daily.dev/posts/initializing-observable-classes-within-the-swiftui-hierarchy-xwf9sc2fk","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/initializing-observable-classes-within-the-swiftui-hierarchy-xwf9sc2fk"},"datePublished":"2026-08-02T07:15:08.459Z","dateModified":"2026-08-02T07:34:36.916Z","description":"A detailed guide on how to correctly initialize and store @Observable classes within SwiftUI views. Covers why @State is necessary to tie observable models to...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/e6eb092d2a6358f35a71123ae8f48573?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/e6eb092d2a6358f35a71123ae8f48573?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Nil Coalescing","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Nil Coalescing","logo":"https://media.daily.dev/image/upload/s--rcEu6sag--/f_auto,q_auto/v1785654899/logos/nilcoalescing?_a=BAMAMicg0","url":"https://daily.dev/sources/nilcoalescing"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/initializing-observable-classes-within-the-swiftui-hierarchy-xwf9sc2fk","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"ios,swift,swiftui","timeRequired":"PT8M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Nil Coalescing","item":"https://daily.dev/sources/nilcoalescing"},{"@type":"ListItem","position":3,"name":"Initializing @Observable classes within the SwiftUI hierarchy"}]}
```

