Alla artiklar
17 november 2026

SwiftUI State, Binding, Observable and Environment: which to use, 2026

Use @State where data lives, @Binding to borrow a value type, @Environment for shared models and @Bindable for bindings into a model.

Node graph in the shape of the Kallos Labs kappa mark on a dotted canvas
Illustration: Kallos Labs.

Pick the wrapper by asking who owns the data. The view that creates it uses @State, a child that only borrows a value type uses @Binding, an observable model shared across many views goes in @Environment, and a view that needs bindings into a model uses @Bindable. If none of those fit, pass the model as a plain property.

That rule covers most screens in an iOS app, and it fits the Observation system Apple added in 2023. Below, each wrapper in turn, the three questions Apple suggests for observable models, and how to move an older ObservableObject codebase over.

Start with the source of truth

Every piece of data in a SwiftUI app should have exactly one owner. Apple's Data Essentials in SwiftUI session frames this as three questions for any view: what data does it need, how will it change that data, and where does the data come from. Apple calls the last one the source of truth and says it is "the most important one in the design of your data model."

Views are cheap and temporary. The same session points out that a new child view is instantiated every time the parent's body runs, so a view cannot be the place where long-lived data is kept by accident. SwiftUI stores the data for you when you mark it with the right wrapper, and everything below is a way to say who the owner is and who is merely borrowing.

State and Binding for value types

@State is the simplest source of truth. Apple's guidance is to use it for transient data owned by the view, such as whether a sheet is showing or what a text field currently holds.

struct ReminderEditor: View {
    @State private var title = ""
    @State private var isUrgent = false

    var body: some View {
        Form {
            TextField("Title", text: $title)
            UrgencyToggle(isOn: $isUrgent)
        }
    }
}

The $ prefix gives you the projected value of the State property, which is a Binding. A Binding is a read-write reference to data that something else owns. The child below does not store its own copy:

struct UrgencyToggle: View {
    @Binding var isOn: Bool

    var body: some View {
        Toggle("Urgent", isOn: $isOn)
    }
}

One mistake shows up often: the child declares its own @State and you pass it the parent's value, and now there are two sources of truth. The 2020 session says it directly: giving a child its own State creates a new source of truth, and edits will not reach the parent. A value type passed as a plain property is only copied, for the same reason.

Use @State where the data lives. Use @Binding where a child must change data it does not own.

Observable models

Once data grows past a few values, you put it in a model class. Since Swift 5.9 the way to do that is the @Observable macro.

@Observable
class ReminderStore {
    var reminders: [Reminder] = []
    var filter = ""
}

Observable types need no property wrapper on their properties, and no @Published. As Apple explains in Discover Observation in SwiftUI, SwiftUI tracks which properties a view's body reads. Only a change to one of those properties updates the view. A list that reads reminders does not redraw when filter changes, which is a real difference from ObservableObject, where a view updates when any published property changes.

The same session reduces the decision to three questions:

  1. Does this model need to be state of the view itself? Use @State.
  2. Does it need to be part of the global environment of the app? Use @Environment.
  3. Does it just need bindings? Use @Bindable.

If every answer is no, store the model as a plain property of the view. A child that only reads values from the model needs nothing more than let store: ReminderStore.

For the view that creates a model, @State works on a class too:

struct RemindersScreen: View {
    @State private var store = ReminderStore()

    var body: some View {
        RemindersList(store: store)
    }
}

This matters for apps that sync data, because a store like this is usually where sync state lives. Our guide to offline-first sync and conflict resolution covers what such a model has to handle.

Environment: data many views need

Threading a model through five views that never touch it is just noise. @Environment lets you inject a value high in the tree and read it where it is needed. With Observation, you supply the object with .environment(_:) and read it by type:

@main
struct RemindersApp: App {
    @State private var store = ReminderStore()

    var body: some Scene {
        WindowGroup {
            RootTabs()
                .environment(store)
        }
    }
}

struct SummaryBadge: View {
    @Environment(ReminderStore.self) private var store

    var body: some View {
        Text("\(store.reminders.count) open")
    }
}

Apple's session says observable types suit the environment well because the updates are based on access: a view that reads only reminders.count updates for that and nothing else. This is also a good fit for navigation state that many screens touch, as in path-driven navigation with NavigationStack.

Keep the environment for data that is truly shared. A model used by one screen and its two children is easier to follow as a plain property.

Bindable: bindings into a model

A TextField needs a Binding, and a model property is not one. @Bindable bridges that gap. In Apple's words it is lightweight: all it does is allow bindings to be created from the type.

struct ReminderRow: View {
    @Bindable var reminder: Reminder

    var body: some View {
        TextField("Title", text: $reminder.title)
    }
}

A model you read from @Environment cannot be used with $ directly. A common workaround, which comes from developer forum answers and not from Apple's documentation, is to declare a local @Bindable copy inside body:

var body: some View {
    @Bindable var store = store
    TextField("Filter", text: $store.filter)
}

Check it against the Xcode version you build with before relying on it.

Migrating from ObservableObject

Apple's migration article states that Observation support starts with iOS 17, iPadOS 17, macOS 14, tvOS 17 and watchOS 10, and the sample code requires Xcode 15. If your app still supports older systems, keep ObservableObject for those targets.

For the rest, the changes are mostly deletions:

BeforeAfter
class Store: ObservableObject@Observable class Store
@Published var itemsvar items
@StateObject private var store = Store()@State private var store = Store()
@ObservedObject var store: Storeplain property, or @Bindable if the view needs bindings
.environmentObject(store).environment(store)
@EnvironmentObject var store: Store@Environment(Store.self) private var store

Use @ObservationIgnored on any property that should not trigger updates. The article also says an app can mix data model types that use different observation systems, so you can migrate one model at a time instead of rewriting everything in a single pull request.

A quick chooser

  • Data this view creates and owns, simple values: @State.
  • Data a parent owns that this child must change: @Binding.
  • A model this view creates: @State on the @Observable instance.
  • A model many views need: @Environment.
  • Bindings into a model's properties: @Bindable.
  • A model the view only reads: a plain property.

Conclusion

One owner per piece of data, and the smallest wrapper that says so. That's the whole system. If you are starting a new app on iOS 17 or later, you can build it with only @State, @Binding, @Environment and @Bindable. If you are weighing how to structure a larger codebase, the same ownership thinking applies to the contract between your app and its backend, which we cover in sharing data contracts between a Next.js backend and a SwiftUI app.

Frequently asked questions

When should I use @State instead of @Binding?

Use @State in the view that creates and owns the data, and @Binding in a child that needs to read and change data its parent owns. If you declare @State in the child as well, you create a second copy that the parent never sees.

Do I still need @StateObject and @EnvironmentObject?

Only for models that still conform to ObservableObject. For @Observable models on iOS 17 and later, Apple's migration guidance replaces @StateObject with @State and @EnvironmentObject with @Environment.

Why does $model.property fail on an @Environment model?

The value read from the environment does not provide bindings by itself. A common fix is to declare a local @Bindable copy inside body, then use the $ syntax on that copy. This pattern comes from developer forum answers, so confirm it with your Xcode version.

Can I mix ObservableObject and @Observable in one app?

Yes. Apple's migration article says an app can mix data model types that use different observation systems, which lets you move one model at a time.