swiftswiftuidata-bindingobservableswift-property-wrapper

SwiftUI – @State vs @Binding


I am learning iOS Programming with Swift and SwiftUI. I know very little and I am very confused about the difference between a @State and a @Binding.

If I understood it correctly, @Binding is just technically @State but it doesn't update the view. If that is the case then why would I need @Binding if I could just use @State to do the same thing?


Solution

  • SwiftUI is a declarative Component-Oriented framework. You have to forget about MVC where you have controllers mediating between view and model. SwiftUI uses diffing algorithm to understand changes and update only corresponding views.

    @State

    @Binding

    @EnvironmentObject