Browse Questions
  • These are SwiftUI's property wrappers for state management — each has a distinct ownership and lifecycle role.
  • Themis is an open-source, cross-platform cryptographic library that packages a few high-level, hard-to-misuse primitives instead of exposing raw ciphers.
  • All three create URLSessionTask subclasses but handle data differently.
  • XCTestExpectation pauses a test until an async condition is fulfilled or a timeout is reached.

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