SwiftUI @State, @Binding

In SwiftUI, both @State and @Binding are property wrappers that are used to manage values within a view.


The main difference between @State and @Binding is that @State triggers a view to redraw whenever the value changes, while @Binding is used to share data between views.



@State is suitable for values that are only used within a single view and don't need to be shared with other views. When a value is changed in a view with @State, SwiftUI will automatically redraw the view to reflect the new value.



@Binding, on the other hand, is used to share data between views. For example, if you have two views and you want to allow the user to modify a value in one view and display the updated value in the other view, you can use @Binding to share the value between the two views. When the value is changed in one view, it will be automatically updated in the other view as well.



So, when working with SwiftUI, it's important to choose the right property wrapper for each situation, based on whether the value needs to be shared between views or not.