Skip to main content
InterviewHubPRO
Section Overview
Q3

Question 3 of 50

Part 1: SwiftUI Architecture, State & App Lifecycle (1 - 10)

6%
iOS Platform & SwiftUI (50 Qs)•Part 1: SwiftUI Architecture, State & App Lifecycle (1 - 10)

What is the difference between `@State` and `@Binding` in SwiftUI?

senior LevelCode ExampleLifecycleSystem Design

In Simple Words:

  • @State: Declares local, private source of truth owned by the view. When the value changes, SwiftUI invalidates the view and re-renders body.
  • @Binding: Two-way reference to state owned by an ancestor/parent view without owning or duplicating the data:
swift
struct ToggleView: View {
    @Binding var isEnabled: Bool // Passed from parent view!

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