SwiftUIMidMCQ

What is the difference between `@State`, `@Binding`, `@ObservedObject`, and `@StateObject`?

Test your knowledge:

Explanation & Code

Answer: These are SwiftUI's property wrappers for state management — each has a distinct ownership and lifecycle role.

WrapperOwns data?Source
@State✅ YesLocal to the view
@Binding❌ NoPassed in from parent
@StateObject✅ YesOwns the ObservableObject
@ObservedObject❌ NoInjected from outside
@EnvironmentObject❌ NoInjected via environment

Code Example:

// Parent creates and owns the object
struct ParentView: View {
    @StateObject private var viewModel = CounterViewModel()

    var body: some View {
        ChildView(count: $viewModel.count) // passes binding
    }
}

// Child receives a binding — does not own the data
struct ChildView: View {
    @Binding var count: Int

    var body: some View {
        Button("Increment") { count += 1 }
    }
}

Key Rule:

  • Use @StateObject when the view creates the object
  • Use @ObservedObject when the object is created elsewhere and passed in

Rate your understanding:

Ready to practice more SwiftUI?

Test yourself with our interactive quiz mode or browse all curated questions for this topic.