# @stateobject

Published articles for @stateobject.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## @StateObject vs. @ObservedObject: The differences explained

DevFeed: [@StateObject vs. @ObservedObject: The differences explained](<https://devfeed.tech/articles/stateobject-vs-observedobject-the-differences-explained-11489.md>)

Original publisher: [Read original article](<https://www.avanderlee.com/swiftui/stateobject-observedobject-differences/>)

Author: Antoine van der Lee

Published: 2026-08-24T14:05:36Z

Content type: article

Language: en

Sources: [SwiftLee](<https://devfeed.tech/sources/swiftlee.md>)

Topics: [SwiftUI](<https://devfeed.tech/topics/swiftui.md>), [iOS](<https://devfeed.tech/topics/ios.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [framework](<https://devfeed.tech/tags/framework.md>), [ios](<https://devfeed.tech/tags/ios.md>), [model](<https://devfeed.tech/tags/model.md>), [observedobject](<https://devfeed.tech/tags/observedobject.md>), [propertywrapper](<https://devfeed.tech/tags/propertywrapper.md>), [published](<https://devfeed.tech/tags/published.md>), [rebuilds](<https://devfeed.tech/tags/rebuilds.md>), [stateobject](<https://devfeed.tech/tags/stateobject.md>), [swiftui](<https://devfeed.tech/tags/swiftui.md>)

### AI overview

This article explains the difference between SwiftUI's @StateObject and @ObservedObject property wrappers. Use @StateObject when a view creates and owns an ObservableObject, and use @ObservedObject when the object is supplied by another view. It also explains how inline object creation can reset view models, contrasts these wrappers with the ObservableObject protocol, and recommends the Observation framework for new code targeting iOS 17 and later.

### Source excerpt

@StateObject and @ObservedObject both connect an ObservableObject to a SwiftUI view. The key difference is ownership: use @StateObject when the view creates the object and @ObservedObject when the view receives it from elsewhere. Choosing the wrong wrapper can cause your model to be recreated whenever SwiftUI rebuilds a view. I made this mistake myself because both wrappers initially appeared to produce the same result. ... -> The post @StateObject vs. @ObservedObject: The differences explained appeared first on SwiftLee.

## Understanding SwiftUI view lifecycles

DevFeed: [Understanding SwiftUI view lifecycles](<https://devfeed.tech/articles/understanding-swiftui-view-lifecycles-21716.md>)

Original publisher: [Read original article](<https://oleb.net/2022/swiftui-view-lifecycle/>)

Author: Ole Begemann

Published: 2022-12-15T20:52:46Z

Content type: tutorial

Language: en

Sources: [Ole Begemann](<https://devfeed.tech/sources/ole-begemann.md>)

Topics: [SwiftUI](<https://devfeed.tech/topics/swiftui.md>), [App](<https://devfeed.tech/topics/app.md>), [Code](<https://devfeed.tech/topics/code.md>), [iOS](<https://devfeed.tech/topics/ios.md>), [macOS](<https://devfeed.tech/topics/macos.md>)

Tags: [app](<https://devfeed.tech/tags/app.md>), [code](<https://devfeed.tech/tags/code.md>), [examples](<https://devfeed.tech/tags/examples.md>), [ios](<https://devfeed.tech/tags/ios.md>), [lifecycle](<https://devfeed.tech/tags/lifecycle.md>), [macos](<https://devfeed.tech/tags/macos.md>), [render](<https://devfeed.tech/tags/render.md>), [screen](<https://devfeed.tech/tags/screen.md>), [state](<https://devfeed.tech/tags/state.md>), [stateobject](<https://devfeed.tech/tags/stateobject.md>), [swiftui](<https://devfeed.tech/tags/swiftui.md>), [view](<https://devfeed.tech/tags/view.md>)

### AI overview

This article explains how SwiftUI view and render trees affect view identity, lifecycle, and state. It describes how state changes can recreate view values while render-tree objects persist, and presents the SwiftUI View Lifecycle app as a way to observe lifecycle events.

### Source excerpt

I wrote an app called SwiftUI View Lifecycle. The app allows you to observe how different SwiftUI constructs and containers affect a view's lifecycle, including the lifetime of its state and when onAppear gets called. The code for the app is on GitHub. It can be built for iOS and macOS. The view tree and the render tree When we write SwiftUI code, we construct a view tree that consists of nested view values. Instances of the view tree are ephemeral: SwiftUI constantly destroys and recreates (parts of) the view tree as it processes state changes. The view tree serves as a blueprint from which SwiftUI creates a second tree, which represents the actual view "objects" that are "on screen" at any given time (the "objects" could be actual UIView or NSView objects, but also other representations; the exact meaning of "on screen" can vary depending on context). Chris Eidhof likes to call this second tree the render tree (the link points to a 3 minute video where Chris demonstrates this duality, highly recommended). The render tree persists across state changes and is used by SwiftUI to establish view identity. When a state change causes a change in a view's value, SwiftUI will find the corresponding view object in the render tree and update it in place, rather than recreating a new view object from scratch. This is of course key to making SwiftUI efficient, but the render tree has another important function: it controls the lifetimes of views and their state. View lifecycles and state We can define a view's lifetime as the timespan it exists in the render tree. The lifetime begins with the insertion into the render tree and ends with the removal. Importantly, the lifetime extends to view state defined with @State and @StateObject: when a view gets removed from the render tree, its state is lost; when the view gets inserted again later, the state will be recreated with its initial value. The SwiftUI View Lifecycle app tracks three lifecycle events for a view and displays the