---
title: ObservedObject
framework: swiftui
role: symbol
role_heading: Structure
path: swiftui/observedobject
---

# ObservedObject

A property wrapper type that subscribes to an observable object and invalidates a view whenever the observable object changes.

## Declaration

```swift
@MainActor @propertyWrapper @preconcurrency @frozen struct ObservedObject<ObjectType> where ObjectType : ObservableObject
```

## Overview

Overview Add the @ObservedObject attribute to a parameter of a SwiftUI View when the input is an ObservableObject and you want the view to update when the object’s published properties change. You typically do this to pass a StateObject into a subview. The following example defines a data model as an observable object, instantiates the model in a view as a state object, and then passes the instance to a subview as an observed object: class DataModel: ObservableObject {     @Published var name = "Some Name"     @Published var isEnabled = false }

struct MyView: View {     @StateObject private var model = DataModel()

var body: some View {         Text(model.name)         MySubView(model: model)     } }

struct MySubView: View {     @ObservedObject var model: DataModel

var body: some View {         Toggle("Enabled", isOn: $model.isEnabled)     } } When any published property of the observable object changes, SwiftUI updates any view that depends on the object. Subviews can also make updates to the model properties, like the Toggle in the above example, that propagate to other observers throughout the view hierarchy. Don’t specify a default or initial value for the observed object. Use the attribute only for a property that acts as an input for a view, as in the above example. note: Don’t wrap objects conforming to the Observable protocol with @ObservedObject. SwiftUI automatically tracks dependencies to Observable objects used within body and updates dependent views when their data changes. Attempting to wrap an Observable object with @ObservedObject may cause a compiler error, because it requires that its wrapped object to conform to the ObservableObject protocol. If the view needs a binding to a property of an Observable object in its body, wrap the object with the Bindable property wrapper instead; for example, @Bindable var model: DataModel. For more information, see Managing model data in your app.

## Topics

### Creating an observed object

- [init(wrappedValue:)](swiftui/observedobject/init(wrappedvalue:).md)
- [init(initialValue:)](swiftui/observedobject/init(initialvalue:).md)

### Getting the value

- [wrappedValue](swiftui/observedobject/wrappedvalue.md)
- [projectedValue](swiftui/observedobject/projectedvalue.md)
- [ObservedObject.Wrapper](swiftui/observedobject/wrapper.md)

## Relationships

### Conforms To

- [DynamicProperty](swiftui/dynamicproperty.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Creating model data

- [Managing model data in your app](swiftui/managing-model-data-in-your-app.md)
- [Migrating from the Observable Object protocol to the Observable macro](swiftui/migrating-from-the-observable-object-protocol-to-the-observable-macro.md)
- [Observable()](observation/observable().md)
- [Monitoring data changes in your app](swiftui/monitoring-model-data-changes-in-your-app.md)
- [StateObject](swiftui/stateobject.md)
- [ObservableObject](combine/observableobject.md)
